php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19738 Getting reference instead of copy of object
Submitted: 2002-10-03 10:15 UTC Modified: 2002-10-27 20:01 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: team at anahoret dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.3 OS: Linux, Windows
Private report: No CVE-ID: None
 [2002-10-03 10:15 UTC] team at anahoret dot com
Normally this code should print "0", 
however, when uncommenting a single empty method call, 
it outputs "1".
It seems like a copy suddenly becomes a reference.

<?php

$a1 = new A();
//$a1->c->f();  // uncomment this to expose error.
$a2 = $a1;
$a2->c->x = 1;
echo $a1->c->x;

class C {
    var $x = 0;
    function f() {}
}

class A {
    var $c;
    function A() { $this->c = new C(); }
}

?>

Thanks. 
Anahoret Team.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-27 19:51 UTC] sterling@php.net
this due to that whole shallow copy thingy... ;-)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 22:01:26 2024 UTC