RE: [PHP] Object In a class
| From: | Justin Mazzi | Date: | Mon, 10 Feb 2003 13:49:21 +0000 |
| Subject: | RE: [PHP] Object In a class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135051@lists.php.net to get a copy of this message | ||
How you can you use an object that is already an instance?
-----Original Message-----
From: John Wells [mailto:jb@sourceillustrated.com]
Sent: Sunday, February 09, 2003 4:21 PM
To: justin@linuxgroup.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] Object In a class
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();
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php