1

请帮我。例如,我有一个类 Foo,它从类 Bar 扩展而来。

    class Bar
    {
          public function __call($func, $args){
               echo "Calling method {$func}";
          }
          public function __callstatic($func, $args){
               echo "Calling static method {$func}";
          }
          public function run(){
               echo "calling Bar::run method \n";
          }
    }
    class Foo extends Bar
    {
          public $objBar;
          public function __construct(){
              $this -> objBar = new Bar();
          }
          public function callViaObject(){
              $this -> objBar -> run();
              $this -> objBar -> run1();
          }
          public function callViaParent(){
              parent::run();
              parent::run1();
          }
    }
    $foo = new foo();
    $foo -> callViaObject(); 
    /* output 
       calling Bar::run method \n
       Calling method run1; */
    $foo -> callViaParent();
    /* output 
       calling Bar::run method \n
       Calling method run1; !! */

这里有一个问题,当我用parent::from子类调用方法,并且父类有一个对象时,调用方法parent::不是静态调用。

那么如何签入Bar课堂,如何调用该方法?我可以检查呼叫类型是 parent:: 吗?

非常感谢大家!!

4

1 回答 1

1

加入private static function run1() {}你的 A 类。

于 2013-03-01T18:53:38.747 回答