php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33591 Reference-Flags not resetted
Submitted: 2005-07-06 16:48 UTC Modified: 2005-07-21 11:09 UTC
From: nobody at somewhere dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.11 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nobody at somewhere dot de
New email:
PHP Version: OS:

 

 [2005-07-06 16:48 UTC] nobody at somewhere dot de
Description:
------------
I don't know about any php-Interna

Somehow a PHP-Variable seems to have a Flag that means "Is a Reference". This Flag is not resetted under the conditions I show in the code below.

Cheers!


Reproduce code:
---------------
#---

global $ar;
$ar= array("[element of ar]");
var_dump($ar);

$ok= f();
$ok[0]= "[i DIDN'T set ar!]";
var_dump($ar);

$bug= & f();
$bug= f(); # bug! doesn't reset reference-flag
$bug[0]= "[i DIDN'T set ar!]";
var_dump($ar);

function & f() {
    global $ar;
    return $ar;
}

exit;

#---

Expected result:
----------------
array(1) { [0]=>  string(15) "[element of ar]" }
array(1) { [0]=>  string(15) "[element of ar]" }
array(1) { [0]=>  string(15) "[element of ar]" }


Actual result:
--------------
array(1) { [0]=>  string(15) "[element of ar]" }
array(1) { [0]=>  string(15) "[element of ar]" }
array(1) { [0]=>  string(18) "[i DIDN'T set ar!]" }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-07-21 10:58 UTC] sl at yes-co dot nl
Output on PHP 5.1.0-dev (Jul 21 2005 08:29:50):

array(1) {
  [0]=>
  string(15) "[element of ar]"
}
array(1) {
  [0]=>
  string(15) "[element of ar]"
}
array(1) {
  [0]=>
  string(18) "[i DIDN'T set ar!]"
}
 [2005-07-21 11:09 UTC] tony2001@php.net
line 1: $bug= & f();
line 2: $bug= f();
line 3: $bug[0]= "[i DIDN'T set ar!]";

on line 1 you're turning $bug to a reference to $ar.
on line 2 you're setting the value of the referenced variable.
on line 3 you're changing the value of $bug (which is still referencing $ar, so $ar gets changed too).

Adding unset($bug) between 1-st & 2-nd lines resolves it, because in this case unset() kills the reference.

No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 03:00:02 2025 UTC