Re: Assigning functions
| From: | Nathan Nobbe | Date: | Fri, 02 May 2008 20:27:55 +0000 |
| Subject: | Re: Assigning functions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-273815@lists.php.net to get a copy of this message | ||
On Fri, May 2, 2008 at 1:48 PM, Nathan Nobbe <quickshiftin@gmail.com> wrote:
> On Fri, May 2, 2008 at 1:09 PM, Philip Thompson <philthathril@gmail.com>
> wrote:
>
>> Hi all. I have several classes. Within each class, a new class is called.
>> Is there a way to assign a function in a *deeper* class to be called in the
>> first class? Example to follow......
>>
>> <?php
>> class A {
>> function __construct () {
>> $this->b = new B ();
>> // I want to do the following. This does not work, of course.
>> $this->doSomething = $this->b->c->doSomething;
>> }
>> }
>>
>> class B {
>> function __construct () {
>> $this->c = new C ();
>> }
>> }
>>
>> class C {
>> function __construct () { }
>> function doSomething () { echo "¡Hi!"; }
>> }
>>
>> $a = new A ();
>> // Instead of doing this,
>> $a->b->c->doSomething();
>>
>> // I want to do this.
>> $a->doSomething(); // ¡Hi!
>> ?>
>>
>> Basically, it's just to shorten the line to access a particular function.
>> But, is it possible?!
>
>
> i cant remember what the term is for it phillip (ill look later)
>
i remember what it is know; the principal of least knowledge ;)
http://en.wikipedia.org/wiki/Law_of_Demeter
-nathan