php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30179 unset deletes array entries and its copied entries
Submitted: 2004-09-21 15:50 UTC Modified: 2004-09-23 14:46 UTC
From: oliver at teqneers dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.8 OS: Suse 9.0
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: oliver at teqneers dot de
New email:
PHP Version: OS:

 

 [2004-09-21 15:50 UTC] oliver at teqneers dot de
Description:
------------
When I copy an array with a normal "=" the copy is not a real copy, but a reference to it. This only seems to happen to cascaded arrays.
When an entry of the original array is unset, the copied entry will be unset as well.

Reproduce code:
---------------
$arr	= array( 'in' => array(1,2,3) );
$copy	= $arr;

print_r($copy);
unset( $arr['in'][1] );
print_r($copy);


Expected result:
----------------
Array
(
    [in] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)

Array
(
    [in] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)



Actual result:
--------------
Array
(
    [in] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)

Array
(
    [in] => Array
        (
            [0] => 1
            [2] => 3
        )

)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-22 00:04 UTC] derick@php.net
Works fine here with 4.3.6, 4.3.8, 4.3.9-dev, 5.0.1 and 5.1.0-dev.
 [2004-09-22 00:30 UTC] oliver at teqneers dot de
This is definately no BOGUS. If you like i can send you 
screenshots or the output of the phpinfo(). You can ask 
Hartmut Holzgraefe about me. I used to work with him and 
I am programming PHP for years. This is a bug and it 
does happen everytime I execute this tiny script.
I sent in live output data.
 [2004-09-22 00:36 UTC] derick@php.net
It still works fine here, and it works fine with every PHP version that I have on my system.
 [2004-09-22 00:42 UTC] oliver at teqneers dot de
But is there any way I can show it to you? because it 
really happens. I haven't seen it before. I already 
tried to d/l and install the 4.3.9RC3 but had the same 
results. Is it possible, that there is a library 
dependency, which might be responsible for that? I can't 
tell the exact point of time, when it occured the first 
time, but it might happen with the last SuSE update.
 [2004-09-22 00:52 UTC] derick@php.net
Provide a shell account? And did you compile from OUR sources, and not the Suse ones?
 [2004-09-22 00:59 UTC] oliver at teqneers dot de
Hi,the shell account is not that easy, because it is a 
company server. But I did not use the SuSE binaries. I 
installed it from the sources. If you like, I could send 
you the compile options tomorrow? does that help?
 [2004-09-22 11:38 UTC] oliver at teqneers dot de
Hi,

I just made the scripts available on our webserver for 
you. If you like you can look at them at:
http://teqneers.dnsalias.com/phpbug/
If made a link to every php-script with .phps, so you 
can see the source code of it.

hope this helps.
 [2004-09-22 21:20 UTC] derick@php.net
I think it might be a problem with the Zend extensions that you loaded, please remove them from your configuration and try again.
 [2004-09-23 11:42 UTC] oliver at teqneers dot de
You were right. It is the Zend Optimizer.
I would never thought, that a binary caching mechanism 
could cause such a problem.

Thank very much for your good and fast support!!!

Can and should I post this at Zend?
 [2004-09-23 14:46 UTC] derick@php.net
You should post it to them. Also marking this as bogus as there is no bug in PHP.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC