note 81174 modified in language.oop5.reflection by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 16:15:09 +0000 |
| Subject: | note 81174 modified in language.oop5.reflection by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160715@lists.php.net to get a copy of this message | ||
I encountered a weird problem with ReflectionFunction, described in ticket 44139 of PHP Bugs.
If for some reason you need to call with invoke, or invokeArgs, a function like array_unshift (that
accepts internally the array by reference) you could use this code to avoid the generated warning or
fatal error.
<?php
function unshift(){
$ref = new ReflectionFunction('array_unshift');
$arguments = func_get_args();
return $ref->invokeArgs(array_merge(array(&$this->arr), $arguments));
}
?>
I don't know about performances (you can create an array manually too, starting from
array(&$this->something) and adding arguments). However, it seems to work correctly without
problems, at least until the send by reference will be usable with one single value ...
--was--
I encountered a weird problem with ReflectionFunction, described in ticket 44139 of PHP Bugs.
If for some reason you need to call with invoke, or invokeArgs, a function like array_unshift (that
accepts internally the array by reference) you could use this code to avoid the generated warning or
fatal error.
<?php
function unshift(){
$ref = new ReflectionFunction('array_unshift');
$arguments = func_get_args();
return $ref->invokeArgs(array_merge(array(&$this->arr), $arguments));
}
?>
I don't know about performances (you can create an array manually too, starting from
array(&$this->something) and adding arguments). However, it seems to work correctly without
problems, at least until the send by reference will be usable with one single value ...
http://php.net/manual/en/language.oop5.reflection.php