1

私はこれに似たクラスを持っています

class x {
  function __construct($file){
   $this->readData = new splFileObject($file); 
 }

 function a (){
  //do something with $this->readData;  
 }

 function b(){
   //do something with $this->readData; 
 }
}

$o = new x('example.txt');
echo $o->a(); //this works
echo $o->b(); //this does not work. 

最初に呼び出されたメソッドのみが機能する場合、それらが一緒に呼び出された場合、最初に呼び出されたメソッドのみが機能するようです。new問題は、オブジェクトがどのように構築されるかを理解していないことに関係していると思います。

4

1 に答える 1