note 108662 deleted from function.call-user-func-array by danbrown

From: Date: Tue, 15 May 2012 22:44:51 +0000
Subject: note 108662 deleted from function.call-user-func-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187999@lists.php.net to get a copy of this message
Note Submitter: descartavel1+php at gmail dot com ---- <?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 ?>

« previous php.notes (#187999) next »