Doc #60140 [Opn->Wfx]: ReflectionMethod::invoke*() does not work for pass-by-ref arguments

From: Date: Thu, 27 Oct 2011 15:39:22 +0000
Subject: Doc #60140 [Opn->Wfx]: 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-7359@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: laruence@php.net Reported by: sebastian@php.net Summary: ReflectionMethod::invoke*() does not work for pass-by-ref arguments -Status: Open +Status: Wont fix 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: <laruence> a work fix for bug60140(invoke, reference) http://pastebin.com/ZYc4yy8P <laruence> but not sure, does it can cause some side-effect. <laruence> however, the ext/reflection tests all passed <johannes_> i doubt it is correct <johannes_> you're setting the isref flag but you might have a copy <johannes_> so do function test(&$param) { $param = 23, } $r = new Reflectionfunction("test"); $a = 42; $b = &$a; $r->invoke($a); <johannes_> and then the result is wrong <johannes_> the way to fix it is to take all paramters by-ref by default and then separate them if needed <johannes_> which has many many many other issues <laruence> en , yes, if that way, $ref->invoke("value") will be broken <johannes_> thanks for trying to fix it (it's an old issue, and it's good to have "new" people thinking about it, sometimes there are new solutions, sometimes these might work) Previous Comments: ------------------------------------------------------------------------ [2011-10-27 11:01:11] sebastian@php.net invokeArgs() works: <?php class Foo { public function bar(&$baz) { } } $array = array(); $object = new Foo; $method = new ReflectionMethod('Foo', 'bar'); $method->invokeArgs($object, array(&$array)); ?> ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#7359) next »