php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77951 ReflectionReference should return null for rc=1 reference
Submitted: 2019-04-29 06:40 UTC Modified: 2019-05-09 10:02 UTC
From: nicolas dot grekas+php at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nicolas dot grekas+php at gmail dot com
New email:
PHP Version: OS:

 

 [2019-04-29 06:40 UTC] 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)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-29 06:48 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2019-04-29 06:48 UTC] 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 07:53 UTC] nicolas dot grekas+php at gmail dot com
-Status: Feedback +Status: Open
 [2019-04-29 07:53 UTC] 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 08:07 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-04-29 08:07 UTC] nikic@php.net
Not sure whether we should return null or add a method to detect singleton references.
 [2019-04-29 08:23 UTC] 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-05-09 10:02 UTC] nikic@php.net
-Summary: ReflectionReference bugs recounting +Summary: ReflectionReference should return null for rc=1 reference
 [2019-05-09 10:03 UTC] nikic@php.net
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
 [2019-05-09 10:03 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 06:01:28 2024 UTC