Re: Assigning functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Philip

First thing first: design patterns are your friend. A good reference
for which, is:

http://www.fluffycat.com/PHP-Design-Patterns/

Second of all. What is the situation in which you are trying to do
this? I can't really think of one where you would do such a thing.

- Craige

On Fri, May 2, 2008 at 3:09 PM, Philip Thompson <philthathril@xxxxxxxxx> 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?!
>
>  Thanks,
>  ~Philip
>  --
>  PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux