Re: pain
| From: | Micah Gersten | Date: | Wed, 10 Sep 2008 21:04:56 +0000 |
| Subject: | Re: pain | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279820@lists.php.net to get a copy of this message | ||
You should read this:
http://us3.php.net/manual/en/language.oop5.overloading.php
The magic method __call passes all the arguments pass to the function
that is not there in 1 array. So every time you execute a function that
is not there and __call is called <grin>, you will add another outer
array. This is also not the normal way to do oop programming.
Normally, you extend a class and use parent::methodName to call a parent
function.
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
Nathan Rixham wrote:
> Not sure why I'm sharing this; but it could be a gotcha
>
> <?php
>
> class testBase {
>
> public function __call( $methodName , $values )
> {
> echo __METHOD__ . PHP_EOL;
> print_r( $values );
> }
>
> }
>
> class testOuter {
>
> private $base;
>
> public function __construct()
> {
> $this->base = new testBase;
> }
> public function __call( $methodName , $values )
> {
> echo __METHOD__ . PHP_EOL;
> print_r( $values );
> $this->base->test( $values );
> }
>
> }
>
> $test = new testOuter;
> $test->test( 'test' );
>
> ?>
>
> output:
> testOuter::__call
> Array
> (
> [0] => test
> )
> testBase::__call
> Array
> (
> [0] => Array
> (
> [0] => test
> )
>
> )
>
> point:
> note the $values keep getting nested into an array one deeper; get's
> frustrating when dealing with passing arrays and detecting whats in
> them! [consider if( count($values) ) or even foreach etc..]!
>