Re: calling parent class method from the outside

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

 



Jochem Maas wrote:
another solution for the OP might be (although I think it goes against all
design principles):

class A {
  function foo() {
    echo "achoo\n";
  }
}

class B extends A {
  function foo() {
    echo "cough\n";
  }
  function __call($meth, $args) {
    $func = array(parent, strtolower(str_replace("parent","", $meth)));
    if (is_callable($func))
      return call_user_func_array($func, $args);
  }
}

$b = new B;
$b->foo();
$b->parentFoo();


Barring the s/parent/get_parent_class/ the idea is really really cute, thanks. Beautiful. Heck, maybe I'll even hack the code to do it like that... after some grace period.

P.S.: I thought calling array('classname', 'method') only worked for static methods? It turns out there's an implied $this being passed around?

--
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