Why can't you call abstract functions from abstract classes in PHP?

前端 未结 3 2028
花落未央
花落未央 2020-12-14 13:56

I\'ve set up an abstract parent class, and a concrete class which extends it. Why can the parent class not call the abstract function?

//foo.php


        
3条回答
  •  萌比男神i
    2020-12-14 14:36

    You notice that word self?

    That is pointing to AbstractClass. Thus it is calling AbstractClass::foo(), not ConcreteClass::foo();

    I believe PHP 5.3 will provide late static bindings, but if you are not on that version, self will not refer to an extended class, but the class that the function is located in.

    See: http://us.php.net/manual/en/function.get-called-class.php

提交回复
热议问题