Bug #78263 [Opn->Csd]: \ReflectionReference::fromArrayElement() returns null while item is a reference
| From: | nikic@php.net | Date: | Mon, 08 Jul 2019 15:25:22 +0000 |
| Subject: | Bug #78263 [Opn->Csd]: \ReflectionReference::fromArrayElement() returns null while item is a reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221660@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78263&edit=1
ID: 78263
Updated by: nikic@php.net
Reported by: nicolas dot grekas+php at gmail dot com
Summary: \ReflectionReference::fromArrayElement() returns
null while item is a reference
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
PHP Version: 7.4Git-2019-07-08 (Git)
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
https://github.com/php/php-src/commit/428cfdd1810b17f0064b7691276f0eb92dc963b6
makes ReflectionReference return non-null for rc=1 references and adds a separate method to check
the refcount, so the user can decide himself whether or not they want to deal with singleton
references.
Previous Comments:
------------------------------------------------------------------------
[2019-07-08 13:33:39] nikic@php.net
Null is returned here because it is an rc=1 reference, as requested in bug #77951. Does that mean
that we should return non-null for rc=1 references after all?
------------------------------------------------------------------------
[2019-07-08 13:13:46] nicolas dot grekas+php at gmail dot com
Description:
------------
See reproducer:
Test script:
---------------
$var = function &() {
$var = [];
$var[] = &$var;
return $var;
};
$var = [$var()];
function isref1(array $a, string $k)
{
return null !== \ReflectionReference::fromArrayElement($a, $k);
}
function isref2(array $a, string $k)
{
$v = $a[$k];
$b = $a;
$b[$k] = $c = new \stdClass();
if ($a[$k] === $c) {
$a[$k] = $v;
return true;
}
return false;
}
var_dump($var);
var_dump([isref1($var[0], 0), isref2($var[0], 0)]);
Expected result:
----------------
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
array(2) {
[0]=>
bool(false)
[1]=>
bool(true)
}
Actual result:
--------------
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
array(2) {
[0]=>
bool(true)
[1]=>
bool(true)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78263&edit=1