php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53525 php version 5.3.0 - error in unset var for when used in function
Submitted: 2010-12-12 09:27 UTC Modified: 2010-12-12 10:49 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: shoja dot mehrdad at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3.4 OS: test in windows vista
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: shoja dot mehrdad at gmail dot com
New email:
PHP Version: OS:

 

 [2010-12-12 09:27 UTC] shoja dot mehrdad at gmail dot com
Description:
------------
$b = array(1, 2, 3);
function b(&$array)
{
  $array[0] = 1000; 
  
       unset($array);   // <=====
  
  $array    = array();   
  $array[1] = 2000;   
}
  b($b);
  print_r($b);

Test script:
---------------
Array
(
    [0] => 1000
    [1] => 2
    [2] => 3
)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-12 10:49 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-12-12 10:49 UTC] cataphract@php.net
Unset deletes the function local variable $array, not the global $b, despite $array and $b being in the same reference set. This is by design. When $array is recreated it already lost its connection to $b.

Note that $array and $b point to the same data, but $array doesn't "know" which other variables (in this case,the global $b) point to this same data its pointing, so it cannot really unset $b.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 00:01:31 2024 UTC