php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61462 array references inconsistency
Submitted: 2012-03-21 10:13 UTC Modified: 2012-03-21 11:56 UTC
From: goetas at lignano dot it Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.10 OS: ubuntu
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: goetas at lignano dot it
New email:
PHP Version: OS:

 

 [2012-03-21 10:13 UTC] goetas at lignano dot it
Description:
------------
i've found this array reference problem.
 

Test script:
---------------
function remTest($array){
	unset($array['a'][0]);
}

$a = array(
	'a'=> array(0=>'test')
);

$b = &$a['a'];


print_r($a);

remTest($a);

print_r($a);

Expected result:
----------------
Array
(
    [a] => Array
        (
            [0] => test
        )

)
Array
(
    [a] => Array
        (
            [0] => test
        )

)

Actual result:
--------------
Array
(
    [a] => Array
        (
            [0] => test
        )

)
Array
(
    [a] => Array
        (
        )

)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-21 10:15 UTC] goetas at lignano dot it
i've also tested modifying the "remTest" function...

function remTest($array){
	unset($array['a']);
}

with this function the code works correctly...
really strange...
 [2012-03-21 10:23 UTC] goetas at lignano dot it
a simpler test case:

$a = array(
	'a'=> array(0=>'test')
);

$b = &$a['a'];
$c = $a;

unset($c['a'][0]); // modifies $a
unset($c['a']); // do not modifies $a
 [2012-03-21 11:56 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2012-03-21 11:56 UTC] cataphract@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

See http://php.net/manual/en/language.references.whatdo.php right above http://pt2.php.net/manual/en/language.references.whatdo.php#language.references.whatdo.pass
 [2012-03-21 12:06 UTC] goetas at lignano dot it
i do not understand why this is not a bug...

$a = array(
  'a'=> array(0=>'test')
);

$b = &$a['a'];
$c = $a;

unset($c['a'][0]); // modifies $a
unset($c['a']); // do not modifies $a

$a is never modified. 
$c should be a complete copy of $a,
if i modify $c, $a should not change.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC