note 108662 added to function.call-user-func-array
| From: | descartavel1+php at gmail dot com | Date: | Tue, 15 May 2012 22:24:42 +0000 |
| Subject: | note 108662 added to function.call-user-func-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187998@lists.php.net to get a copy of this message | ||
<?php
class A {
| private $str = "hello world\n";
| public function b(){
| | # this is a static safe function, but not defined static
| | echo "b() hello world\n";
| }
| public function c(){
| | echo $this->str;
| }
| public static function s(){
| | # proper static function
| | echo 's';
| }
}
$a = new A();
$aa = new A;
var_dump(is_callable('A::b')); // false
var_dump(is_callable('A::s')); // true
var_dump(is_callable(array($a, 'b'))); // true
var_dump(is_callable(array($aa, 'b'))); // true
var_dump(is_callable(array('A', 'b'))); // true
var_dump(is_callable(array('A', 'c'))); // true *but see below*
call_user_func( array($a, 'c') ); // works
call_user_func( array('A', 'b') ); //works
call_user_func( array('A', 'c') ); // PHP Fatal error: Using $this when not in
object context
call_user_func_array( array($a, 'c'), array() ); //works
call_user_func_array( array('A', 'b'), array() ); // only works in a
'static-safe' function
call_user_func_array( array('A', 'b'), array() ); // PHP Fatal error: Using
$this when not in object context
?>
----
Server IP: 192.41.42.26
Probable Submitter: 209.131.61.1
----
Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php
Edit -- https://master.php.net/note/edit/108662
Del: integrated -- https://master.php.net/note/delete/108662/integrated
Del: useless -- https://master.php.net/note/delete/108662/useless
Del: bad code -- https://master.php.net/note/delete/108662/bad+code
Del: spam -- https://master.php.net/note/delete/108662/spam
Del: non-english -- https://master.php.net/note/delete/108662/non-english
Del: in docs -- https://master.php.net/note/delete/108662/in+docs
Del: other reasons-- https://master.php.net/note/delete/108662
Reject -- https://master.php.net/note/reject/108662
Search -- https://master.php.net/manage/user-notes.php