在 PHP 5.2 中,当我对一个非静态方法使用 call_user_func
时,会收到严格警告:
Strict Standards: Non-static method User::register() cannot be called statically
在 PHP 5.3.1 上,我没有收到这个警告。这是 PHP 5.3.1 的一个错误还是被移除了该警告?
class MyClass {
public function hello() {
echo "Hello, World!";
}
}
$a = new MyClass();
call_user_func(array($a, 'hello'));
call_user_func('MyClass::hello');
Strict standards: `call_user_func()` expects parameter 1 to be a valid callback,
non-static method `MyClass::hello()` should not be called statically
一个实例化对象的方法被传递为一个包含对象在索引0处和方法名称在索引1处的数组。
E_ALL
包括E_STRICT
从PHP 5.4.0开始(引用):E_ALL
确实包括E_STRICT
。 - Scott Arciszewskicall_user_func( [ ( new MyClass() ), 'hello' ] );
- Alexey
error_reporting
。 - vooD