Bug #80991 [Opn->Csd]: There is no way to revoke reflection method with by-reference args
| From: | g dot sokol99 at g-sokol dot info | Date: | Mon, 26 Apr 2021 15:02:16 +0000 |
| Subject: | Bug #80991 [Opn->Csd]: There is no way to revoke reflection method with by-reference args | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233581@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80991&edit=1
ID: 80991
User updated by: g dot sokol99 at g-sokol dot info
Reported by: g dot sokol99 at g-sokol dot info
Summary: There is no way to revoke reflection method with
by-reference args
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: linux
PHP Version: 7.4.16
Block user comment: N
Private report: N
New Comment:
Oh, there is workaround:
```
$target->invokeArgs(null, [&$arg]);
```
Previous Comments:
------------------------------------------------------------------------
[2021-04-26 15:01:45] g dot sokol99 at g-sokol dot info
Oh, there is workaround:
```
$target->invokeArgs(null, [&$arg]);
```
------------------------------------------------------------------------
[2021-04-26 14:58:00] g dot sokol99 at g-sokol dot info
Description:
------------
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');
$target->setAccessible(true);
$arg = [];
$target->invoke(null, &$arg);
var_exoprt($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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80991&edit=1