Re: Can a class instance a property of another class
| From: | Ken Kixmoeller -- reply to ken@kixmoeller.com | Date: | Sat, 27 Jan 2007 21:10:50 +0000 |
| Subject: | Re: Can a class instance a property of another class | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247898@lists.php.net to get a copy of this message | ||
OK, Jochem, I adapted your example and got it working. Thank you very much.
I am still playing with it to better understand. One thing I don't yet understand is the necessity for the getFoo()/getBar() "handshake," especially the getbar() in the BAR class. That doesn't seem to serve any purpose. My adaptation us just a getDummy().
Do they just serve to pass the object by reference?
Ken
--------------------------------------------------------------
On Jan 26, 2007, at 5:47 PM, Jochem Maas wrote:
class Foo { private $var; function __construct() { $this->var = "foo"; } function getFoo() { return $this->var; } } class Bar { private $var; private $foo; function __construct() { $this->var = "bar"; $this->foo = new Foo; } function getBar() { return $this->var; } function speak() { echo "I am ",$this->foo->getFoo(),$this->getBar(),"\n"; } }