ID:               27268
 Updated by:       [EMAIL PROTECTED]
 Reported By:      lingwitt at bellsouth dot net
-Status:           Verified
+Status:           Assigned
 Bug Type:         Zend Engine 2 problem
 Operating System: *
-PHP Version:      5CVS-2005-04-30
+PHP Version:      5CVS-2005-06-19
-Assigned To:      
+Assigned To:      dmitry
 New Comment:

Still happens..



Previous Comments:
------------------------------------------------------------------------

[2005-05-25 12:32:37] ericvanblokland at gmail dot com

Isn't this related to

http://bugs.php.net/bug.php?id=24485

when copies become references? (Clone should copy variables from an
object, but because of the bug mentioned above, variables can no longer
be copied, just referenced)

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

[2004-02-15 23:47:13] lingwitt at bellsouth dot net

In fact, the reference doesn't need to be made in a 
method:

class A
{
    var $a = array();
    
    public function &getA()
    {
        return $this->a;
    }
}

$A = new A;
$A->a = array(1);
$array = $A->getA();
$clone = clone $A;
$clone->a = array();

print_r($A);

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

[2004-02-15 21:06:03] lingwitt at bellsouth dot net

Description:
------------
When an object's method calls upon another one of its 
methods such that the second method returns a reference 
that is stored in the the first method as a local 
variable, then the reference persists in some way so as 
to make cloning problematic.

As a result, a modification to the referenced variable 
in the clone cuases a modification to the same variable 
in original.

Reproduce code:
---------------
class A
{
    var $a = array();
    
    public function makeAReference()
    {
        $array = $this->getA();
    }
    
    public function &getA()
    {
        return $this->a;
    }
}

$A = new A;
$A->a = array(1);
$A->makeAReference();
$clone = clone $A;
$clone->a = array();

print_r($A);

Expected result:
----------------
This is gotten when $A->makeAReference() is removed.

A Object
(
    [a] => Array
        (
            [0] => 1
        )

)

Actual result:
--------------
Obviously the modification made it back to the original.

A Object
(
    [a] => Array
        (
        )

)


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


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

Reply via email to