在PHP5.4中,使用$this作为参数调用_user_func

在PHP5.4中,使用$this作为参数调用_user_func,php,oop,php-5.4,Php,Oop,Php 5.4,我需要调用一个动态函数并发送当前对象作为所述函数中的引用 在PHP5.3中,与PHP5.4相反,这是可行的: $value = call_user_func("MyFunction", $value, $row, $this,etc....); // using $this because this call happends inside an object 其中MyFunction是: function MyFunction($value,&$row,&$column,&a

我需要调用一个动态函数并发送当前对象作为所述函数中的引用

在PHP5.3中,与PHP5.4相反,这是可行的:

$value = call_user_func("MyFunction", $value, $row, $this,etc....); // using $this because this call happends inside an object
其中MyFunction是:

function MyFunction($value,&$row,&$column,&$grid,etc...){
    ...
}// myFunction is a standalone function, not inside any object
在PHP5.4中,我得到一个错误“参数应该是一个引用,给定值”。 相应的错误引用call\u user\u func行中的$this参数。 似乎如果我在调用中直接指定$this,它会被视为传递值,因为如果我这样做,它会起作用:

$that = &$this;
$value = call_user_func("MyFunction", $value, $row, $that,etc....);
我必须对所有其他与当前对象相关的参数进行处理


问:还有其他更优雅的方法吗?我遗漏了什么吗?

首先不需要通过引用接受参数。将您的功能更改为:

function MyFunction($value, $row, $column, $grid, ..) ..

不管怎么说,对象值本质上是引用,通过引用传递它们实际上不会添加任何内容,也可能不会像您认为的那样做。

没错!我忘了:)