php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21711 Class owners
Submitted: 2003-01-17 07:14 UTC Modified: 2003-02-25 13:12 UTC
From: klar at nm dot ru Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.0 OS: WIN2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: klar at nm dot ru
New email:
PHP Version: OS:

 

 [2003-01-17 07:14 UTC] klar at nm dot ru
<?
class class_root
{
	var $a;
	var $b;
	function class_root()
	{
		echo get_class($this)." Created<br>";
	}
}

class db_class extends class_root
{
	var $owner;
	function db_class($ow)
	{
		$this->class_root();
		$this->owner=$ow;
	}
}

class adm_class extends class_root
{
	var $owner;
	function adm_class($ow)
	{
		$this->class_root();
		$this->owner=$ow;
	}
	function kkk()
	{
		echo get_class($this->owner)."<br>";
		echo get_class($this->owner->adm)."<br>";//Undefined ??? ... must be object
		echo get_class($this->owner->db)."<br>";//Undefined ??? ... must be object
		$this->owner->adm->kkk();
	}
}

class super_class extends class_root
{
	var $s;
	var $adm;
	var $db;
	function super_class()
	{
		$this->class_root();
		$this->adm=new adm_class(&$this);
		$this->db=new db_class(&$this);	
	}
}

$sc=new super_class();
$sc->adm->kkk();

echo '-------';
?>

results:

super_class Created
adm_class Created
db_class Created
super_class


Fatal error: Call to a member function on a non-object in bla-bla-bla\1.php on line 35


PHP works as apache2 module

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-25 13:12 UTC] moriyoshi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

<?
class foo
{
	var $owner;

	function foo(&$owner) {
		$this->owner = &$owner; // the owner object   needs to be assigned as a
								// reference here, instead of a copy.
	}
}

class bar
{
	var $foo;

	function bar() {
		$this->foo = &new foo($this);
	}
}

$b = new bar();
var_dump($b->foo->owner->foo);
?>

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 18:01:28 2024 UTC