Re: About the magic function __call

From: Date: Wed, 27 Aug 2008 19:49:22 +0000
Subject: Re: About the magic function __call
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-278831@lists.php.net to get a copy of this message
On Wed, Aug 27, 2008 at 1:35 PM, Paulo Sousa <paulo.sousa.filho@gmail.com>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

« previous php.general (#278831) next »