php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12365 Problems with classes and links to objects
Submitted: 2001-07-25 10:11 UTC Modified: 2001-11-17 13:47 UTC
From: vbv at arte dot ru Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.6 OS: Linux
Private report: No CVE-ID: None
 [2001-07-25 10:11 UTC] vbv at arte dot ru
<?
phpinfo();
class a {
	
	function a ($obj) {
		$this->h = &$obj;
		return true;
	}
}

class b {
	var $d=1;
	var $item;
	
	function b () {
		$this->item = new a (&$this);
		$this->d++;
		echo $this->d.'//'.$this->item->h->d.'<br>';	}
	
	function c () {
		$this->item = new a (&$this);
	}
}

$b = new b ();
//$b->c (); //****
$b->d++;
echo $b->d.'--'.$b->item->h->d;


/*
Try to comment and recomment line ****
I see there is a bug with that sitution:
after finishing of object "b" constructor, link $a->h not linked to "b" object and $a->h is a copy of object "b".
I think, this is not right. In constructor $a->h is still link to "b", but after finishing the $a->h is a copy of "b".
*/

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-17 13:47 UTC] mfischer@php.net
The object $this used in the constructor is not the same as the one returned to $b because it got copied. Assign the new object by reference to $b:

  $b = &new b();

Closed.
 [2001-11-17 13:47 UTC] mfischer@php.net
I said closed :-)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC