Re: Inheritance problem

From: Date: Sun, 01 Dec 2002 13:51:14 +0000
Subject: Re: Inheritance problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126599@lists.php.net to get a copy of this message
At 13:05 01.12.2002, Bernard Chamberland said: --------------------[snip]-------------------- >Hi, --------------------[snip]-------------------- [...omitting long code post...] Bernard, couple of things: a) Class "Ressource" uses instance data ("$this->") in the constructor. You shouldn't call this as a static method (see derived class "Plant"). b) Class "Plant": use the commented-out method in the constructor to access the ressource's instance data. You should get an error otherwise ($this is not defined for Ressource::Ressource). c) Now to your original question: your problem is the class constructor for "Rain" which receives a COPY of $jungle, not a HANDLE (PHP-speak: not a REFERENCE) to the jungle object. You should code your Rain constructor like this: function Rain(&$jungle) { $this->jungle = $jungle); } This should give you the correct results as far as I can see. If you miss out passing a REFERENCE instead of a VARIABLE (which would be a COPY of the jungle object), rain falls in the copied jungle, and your original jungle remains dry. Hope this gets you started. As a rule of thumb, always pass REFERENCES when you're dealing with object handles. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#126599) next »