From:             petermiller1986 at gmail dot com
Operating system: ubuntu 10.04
PHP version:      5.3.20
Package:          *General Issues
Bug Type:         Bug
Bug description:php unset local reference affecting global scope

Description:
------------
i have come across some very strange php behaviour. an unset which should
occur within local scope is affecting the scope of the caller function. if
you run the test script you will see that the value 'first value' has been
unset from the $data array in the global scope. however if you comment out
the $in_ref =& $in['level1']; line then the result changes (and it
shouldn't i think).

is this intended behaviour of php or a bug?


Test script:
---------------
<?php
function should_not_alter($in)
{
    $in_ref =& $in['level1']; //try commenting out this line to see the
output change
    should_only_unset_locally($in);
    return $in;
}
function should_only_unset_locally($in)
{
    unset($in['level1']['level2_0']);
}
$data = array('level1' => array('level2_0' => 'first value', 'level2_1' =>
'second value'));
$data = should_not_alter($data);
print_r($data);
?>

Expected result:
----------------
Array
(
    [level1] => Array
        (
            [level2_0] => first value
            [level2_1] => second value
        )

)

Actual result:
--------------
Array
(
    [level1] => Array
        (
            [level2_1] => second value
        )

)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=63865&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63865&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63865&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63865&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63865&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63865&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63865&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63865&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63865&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63865&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63865&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63865&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63865&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63865&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63865&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63865&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63865&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63865&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63865&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63865&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63865&r=mysqlcfg

Reply via email to