From:             lingwitt at bellsouth dot net
Operating system: Mac OS X
PHP version:      5.0.0b4 (beta4)
PHP Bug Type:     Class/Object related
Bug description:  Bad references accentuated by clone

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 bug report at http://bugs.php.net/?id=27268&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27268&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27268&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27268&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27268&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27268&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27268&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27268&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27268&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27268&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27268&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27268&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27268&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27268&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27268&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27268&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27268&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27268&r=float

Reply via email to