Edit report at https://bugs.php.net/bug.php?id=61462&edit=1

 ID:                 61462
 Comment by:         goetas at lignano dot it
 Reported by:        goetas at lignano dot it
 Summary:            array references inconsistency
 Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   ubuntu
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-03-21 11:56:27] cataphr...@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 10:23:24] 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 10:15:19] 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:13:08] 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
        (
        )

)



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61462&edit=1

Reply via email to