Bug #77951 [Asn->Csd]: ReflectionReference should return null for rc=1 reference

From: Date: Thu, 09 May 2019 10:03:42 +0000
Subject: Bug #77951 [Asn->Csd]: ReflectionReference should return null for rc=1 reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220794@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77951&edit=1 ID: 77951 Updated by: nikic@php.net Reported by: nicolas dot grekas+php at gmail dot com Summary: ReflectionReference should return null for rc=1 reference -Status: Assigned +Status: Closed Type: Bug Package: Reflection related PHP Version: Next Minor Version Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=54be40113d77f41cbf5a5078a265279140511c52 Log: Fixed bug #77951 Previous Comments: ------------------------------------------------------------------------ [2019-04-29 08:23:00] nicolas dot grekas+php at gmail dot com Returning null looks the most sensible to me: I'm not sure I known any way to make something usefull with zval that have is_ref=1+refcount=1. In userland, this doesn't make any difference with is_ref=0+refcount=1, does it? ------------------------------------------------------------------------ [2019-04-29 08:07:26] nikic@php.net Not sure whether we should return null or add a method to detect singleton references. ------------------------------------------------------------------------ [2019-04-29 07:53:56] nicolas dot grekas+php at gmail dot com I'm using devilbox-php-fpm-7-4 docker image, freshly pulled php -v returns: PHP 7.4.0-dev (cli) (built: Apr 28 2019 22:36:49) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies ------------------------------------------------------------------------ [2019-04-29 06:48:25] requinix@php.net It's working for me, with both 7.4 and 8.0 built earlier today. What version/commit are you testing with? ------------------------------------------------------------------------ [2019-04-29 06:40:40] nicolas dot grekas+php at gmail dot com Description: ------------ ReflectionReference must have a bug with zval that have is_ref=1 but refcount=1 Test script: --------------- $a = [1, 2]; foreach ($a as &$v) { } // This should return null but instead it returns a ReflectionReference. // a few lines below, $b[0] becomes a reference to $a[0] // while this is not the case when this line is commented. $r = ReflectionReference::fromArrayElement($a, 0); $b = $a; $b[0] = 123; var_dump($a); var_dump($b); Expected result: ---------------- array(2) { [0]=> int(1) [1]=> &int(2) } array(2) { [0]=> int(123) [1]=> &int(2) } Actual result: -------------- array(2) { [0]=> &int(123) [1]=> &int(2) } array(2) { [0]=> &int(123) [1]=> &int(2) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77951&edit=1

« previous php.bugs (#220794) next »