Re: Object In a class

From: Date: Sun, 09 Feb 2003 21:21:03 +0000
Subject: Re: Object In a class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134971@lists.php.net to get a copy of this message
Justin Mazzi said: > Can anyone tell me how to use an object within an object. Example > > > class blah { > var $test; > var $test2; > > function test() { > $this->do(); > } > > } > > > then you want to use that class in a new one. > > > class blah2 { > var $test; > var $test2; > > function do() { > $blah = new blah(); > } > > } > Well, you could use the blah object you created exclusively in function do(), or you could create it as a attribute of your class and use it in your instantiated objects, as: class blah2 { var $test; var $test2; var $myBlah; function blah2() { $this->myBlah = new blah(); } function do() { $this->myBlah->test(); } } $myobj = new blah2(); $myobj->do();

« previous php.general (#134971) next »