Re: About the magic function __call

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

 



On Wed, Aug 27, 2008 at 1:35 PM, Paulo Sousa <paulo.sousa.filho@xxxxxxxxx>wrote:

> Hi there!
>
> I'm working with the following code:
>
> <?php
>
> abstract class Foo{
>
> protected $a;
> protected $b;
> protected $c;
>
>  function __construct($arg){
>  $this->a = $arg;
>  }
>
>  function __call($function, $args){
>  $this->b = $function;
>  $this->c = $args;
>  $this->doWhatever();
>  }
>
>  private doWhatever(){
>  }
> }
>
>
> class Boo extends Foo{
>
> protected $e;
>
> public function __construct(){
>  parent::__construct('Blah');
>  }
>
> public function drive(){
>  $e = 'testing';
>  parent::drive($e);
>  }
> }
>
>
> $br = new Boo();
> $br->drive();
>
>
>
> But I get a Fatal error: Call to undefined method Foo::drive()
>
> The magic fuction __call don't catch the "drive()". Why not?
>
> I need another idea for this problem and avoid edit the abstract class.


looks like __call() might not work through a subclass if defined in the
parent; i might poke around in the .phpt tests that come w/ the php source
to ensure this is the correct behavior.

in the meantime you can get away w/ some variant this ugliness,

class B extends A {
    function __call($method, $args) {
        return parent::__call($method, $args);
    }
}

-nathan

[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