How do I get a PHP class constructor to call its parent's parent's constructor?

前端 未结 15 1443
滥情空心
滥情空心 2020-11-28 21:38

I need to have a class constructor in PHP call its parent\'s parent\'s (grandparent?) constructor without calling the parent constructor.

//         


        
15条回答
  •  时光说笑
    2020-11-28 21:58

    You must use Grandpa::__construct(), there's no other shortcut for it. Also, this ruins the encapsulation of the Papa class - when reading or working on Papa, it should be safe to assume that the __construct() method will be called during construction, but the Kiddo class does not do this.

提交回复
热议问题