hp
hp
<code class="php">class Father { public function __construct() { echo "father<br>"; } } class Child extends Father { public function say() { echo "hello"; } static function say2() { echo "hello2"; } } // 调用对象方法需要先实例化对象 $child = new Child; call_user_func([$child, 'say']); // 可以直接调用类静态方法 call_user_func(['child', 'say2']);</code>
It is a wrong way to write the object method directly by calling the static method of the class. Before PHP5.5 (it seems), it would try its best to satisfy the requirements and then report a warning, but after 5.5, it is an error.
When you use the call_user_func
method, you are using the function in the class, so you need to instantiate it. Only if you write it directly as a method can you write it like you did, for example:
<code>function develop($val){ if($val){ echo 'Successful'; } else { echo 'Fail'; } } call_user_func('develop', true);</code>
The way you write it should be to call a static method
If you want to call an instance method
you have to instantiate the class
Strict mode, pay attention to the php version.