php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17239 Objects copying
Submitted: 2002-05-15 05:48 UTC Modified: 2002-06-01 09:39 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:4 of 5 (80.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: vbv at arte dot ru Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vbv at arte dot ru
New email:
PHP Version: OS:

 

 [2002-05-15 05:48 UTC] vbv at arte dot ru
There is a bug with getting copy of object where 1th object has another 2th object and 2th object has another 3th object.
When i copy 2th object to any variable i must have 2th object in 1th and 2th object in variable. It must be equals but not 2 links to one object.
Look at this code and make changes as recommends in conmment.

<?
class a {
	var $i;
	function a () {
		$this->i = 1;
	}
	function set_i ($p) {
		$this->i = $p;
	}
	function get_i () {
		return $this->i;
	}
}

class b {
	function b () {
		$this->a = new a ();
	}
	function set_id ($p) {
		$this->a->set_i ($p);
	}
	
	function get () {
		return $this->a->get_i ();
	}
}

class c {
	function c () {
		$this->item = new b ();
	}
}

$cat= new c();
$z1 = $cat->item;  // Comment this line
$cat->item->set_id (12);

$z = $cat->item->a;
//$z1 = $cat->item; // Decomment this line
$cat->item->set_id (17);

echo "<br>C: i: ".$cat->item->get();
echo "<br>Z: i: ".$z->get_i ();
echo "<br>Z: i: ".$z1->get ();
if ($cat->item->get() == $z1->get ()) echo " - <font color=red>Getting BUG here. There must be '1' value!</font>";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-01 09:39 UTC] mfischer@php.net
This is no longer an issue with ZE2 in which case every echo returns '17' which is the expected behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 21:01:28 2024 UTC