Re: [PHP4BETA] how to access objects parent?
| From: | waldschrott | Date: | Wed, 10 May 2000 16:02:57 +0000 |
| Subject: | Re: [PHP4BETA] how to access objects parent? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-14758@lists.php.net to get a copy of this message | ||
:) you´re right it´s accessing $bigmama via the local scope, but that´s only possible setting
$bigmama->worm->super=&$bigmama;
from the scope where $bigmama is available, as you did,
but I searched for a way doing this entirely from inside the parasite´s function.
What if I need that $super already in my constructor? Then you method will fail too I think...
regards
wald
Stewart.Taylor@rdel.co.uk (Stewart Taylor) wrote:
In the function Eat() Parasite is accessing $bigmama in local scope via the super property. <? class Cake { var $name="cake"; } class Mama { var $worm; var $food; function GetFood() { return $this->food->name; } } class Parasite { var $super; function Eat() { $this->super->food=""; } }; $bigmama =new Mama(); $bigmama->food=new Cake(); $bigmama->worm = new Parasite(); $bigmama->worm->super=&$bigmama; echo "1".$bigmama->GetFood()."<BR>"; $bigmama->worm->Eat(); echo "2".$bigmama->GetFood(); ?> -----Original Message----- From: waldschrott [mailto:waldschrott@kiffen.de] Sent: 10 May 2000 15:57 To: Stewart Taylor; php4beta Subject: Re: [PHP4BETA] how to access objects parent? ...great idea that shouldn´t steal performance like global does. It´s a solution, but implementing a super like operator (if not already implemented) would be better. In fact you CAN only do this, if you´re on the scope where $bigmama is available, the solution I need is, that the worm (parasite) can access $ bigmama from it´s lokal scope... Stewart.Taylor@rdel.co.uk (Stewart Taylor) wrote: Might you create an propery called super in parasite. class parasite { var $super; ... then use super as an alias of $bigmama $bigmama->worm = new parsite(); $bigmama->worm->super = &$bigmama; Regards, Stewart.