note 98931 added to function.forward-static-call-array
| From: | dot) | Date: | Fri, 16 Jul 2010 11:40:48 +0000 |
| Subject: | note 98931 added to function.forward-static-call-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170898@lists.php.net to get a copy of this message | ||
call_user_func_array() and forward_static_call_array() doesn't give the same result.
In reference to the example:
call_user_func_array(array('A', 'test'), array('more',
'args')) calls the static function 'test()' in class 'A' (like
A::test('more', 'args')).
But forward_static_call_array(array('A', 'test'), array('more',
'args')) calls 'test()' from class 'A' as a method of class
'B'.
An example for better understandig:
<?php
class A
{
const NAME = 'A';
public static function test() {
$args = func_get_args();
echo static::NAME, " ".join(',', $args)." \n";
}
}
class B extends A
{
const NAME = 'B';
public static function test() {
echo self::NAME, "\n";
call_user_func_array(array('A', 'test'), array('more',
'args'));
forward_static_call_array(array('A', 'test'), array('more',
'args'));
}
}
B::test('foo');
?>
Output:
B
A more,args
B more,args
Greetz Stefan
----
Server IP: 85.214.154.209
Probable Submitter: 213.211.246.192
----
Manual Page -- http://www.php.net/manual/en/function.forward-static-call-array.php
Edit -- https://master.php.net/note/edit/98931
Del: integrated -- https://master.php.net/note/delete/98931/integrated
Del: useless -- https://master.php.net/note/delete/98931/useless
Del: bad code -- https://master.php.net/note/delete/98931/bad+code
Del: spam -- https://master.php.net/note/delete/98931/spam
Del: non-english -- https://master.php.net/note/delete/98931/non-english
Del: in docs -- https://master.php.net/note/delete/98931/in+docs
Del: other reasons-- https://master.php.net/note/delete/98931
Reject -- https://master.php.net/note/reject/98931
Search -- https://master.php.net/manage/user-notes.php