2012-12-19 74 views
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(); 
     } 
} 

所以换句话说,我想动态设置对象名称和潜在的方法从我的类中预先存在的属性。

任何想法?

回答

3

生成因为下面的行的错误:

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

替换为:

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