|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80991 There is no way to revoke reflection method with by-reference args
Submitted: 2021-04-26 14:58 UTC Modified: 2021-04-27 12:03 UTC
From: g dot sokol99 at g-sokol dot info Assigned: cmb (profile)
Status: Not a bug Package: Reflection related
PHP Version: 7.4.16 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
49 - 35 = ?
Subscribe to this entry?

 [2021-04-26 14:58 UTC] g dot sokol99 at g-sokol dot info
If we have some method that receives some arguments my reference, there is no way to invoke it with reflection.

Test script:
class TestReflectionMethodInvokeWithReferences
    private static function testTarget(array &$a): void
        $a['new_key'] = 'new value';

// Unit test use case
$testReflectionMethodInvokeWithReferences = new ReflectionClass(TestReflectionMethodInvokeWithReferences::class);
$target = $testReflectionMethodInvokeWithReferences->getMethod('testTarget');
$arg = [];
$target->invoke(null, &$arg);

Expected result:
array (
  'new_key' => 'new value',

Actual result:
PHP Parse error:  syntax error, unexpected token "&", expecting ")" in php shell code on line 5


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-26 15:01 UTC] g dot sokol99 at g-sokol dot info
Oh, there is workaround:
$target->invokeArgs(null, [&$arg]);
 [2021-04-26 15:02 UTC] g dot sokol99 at g-sokol dot info
-Status: Open +Status: Closed
 [2021-04-26 15:02 UTC] g dot sokol99 at g-sokol dot info
Oh, there is workaround:
$target->invokeArgs(null, [&$arg]);
 [2021-04-26 15:50 UTC]
-Status: Closed +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-04-26 15:50 UTC]
Right, you can use ::invokeArgs() instead.  The documentation of
::invoke() refers to call_user_func(), and there this issue is
documented for the $args parameter[1].

[1] <>
 [2021-04-27 12:03 UTC]
-Type: Bug +Type: Documentation Problem
 [2021-04-27 12:03 UTC]
Re-opening as doc problem.
 [2021-04-27 12:03 UTC]
The following pull request has been associated:

Patch Name: Add note for passing references to invoke methods.
On GitHub:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 12 11:01:32 2024 UTC