Doc #60140 [Opn]: ReflectionMethod::invoke*() does not work for pass-by-ref arguments
| From: | sebastian@php.net | Date: | Thu, 27 Oct 2011 11:01:11 +0000 |
| Subject: | Doc #60140 [Opn]: ReflectionMethod::invoke*() does not work for pass-by-ref arguments | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7357@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60140&edit=1
ID: 60140
Updated by: sebastian@php.net
Reported by: sebastian@php.net
Summary: ReflectionMethod::invoke*() does not work for
pass-by-ref arguments
Status: Open
Type: Documentation Problem
Package: Reflection related
Operating System: Irrelevant
PHP Version: 5.3SVN-2011-10-26 (SVN)
Block user comment: N
Private report: N
New Comment:
invokeArgs() works:
<?php
class Foo
{
public function bar(&$baz)
{
}
}
$array = array();
$object = new Foo;
$method = new ReflectionMethod('Foo', 'bar');
$method->invokeArgs($object, array(&$array));
?>
Previous Comments:
------------------------------------------------------------------------
[2011-10-27 10:59:11] cataphract@php.net
Not a bug, it should probably be documented that invoke doesn't support calling the underlying
method with by-ref arguments and invokeArgs should be used instead.
------------------------------------------------------------------------
[2011-10-26 11:05:55] sebastian@php.net
Description:
------------
ReflectionMethod::invoke*() does not work for methods that expect pass-by-reference arguments.
Test script:
---------------
<?php
class Foo
{
public function bar(&$baz)
{
}
}
$array = array();
$object = new Foo;
$method = new ReflectionMethod('Foo', 'bar');
$method->invoke($object, $array);
?>
Actual result:
--------------
Warning: Parameter 1 to Foo::bar() expected to be a reference, value given in /home/sb/test.php on
line 13
Fatal error: Uncaught exception 'ReflectionException' with message 'Invocation of
method Foo::bar() failed' in /home/sb/test.php:13
Stack trace:
#0 /home/sb/test.php(13): ReflectionMethod->invoke(Object(Foo), Array)
#1 {main}
thrown in /home/sb/test.php on line 13
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60140&edit=1