1

クラスのプロパティの値を動的メソッド名として使用する必要がありますが、次のようになります。

 Catchable fatal error: Object of class dispatcher could not be converted to string in ...

私がやりたいことは次のとおりです。

 class test {
      var $objectname = "object_name";
      var $methodname = "method";

      public function test_method() {
           require_once("some_class_file");
           // Here is where I am falling out:
           $some_object = new $this->objectname();
           $some_object->$this->methodname();
      }
 }

つまり、クラスの既存のプロパティからオブジェクト名と潜在的なメソッドを動的に設定したいと考えています。

何か案は?

4

1 に答える 1

3

次の行が原因でエラーが生成されました:

 $some_object->$this->methodname();

と置換する :

 $some_object->{$this->methodname}();
于 2012-12-19T20:14:19.890 に答える