Fatal error: Declaration of .. must be compatible with .. PHP

后端 未结 4 1646
無奈伤痛
無奈伤痛 2020-12-10 01:54

I\'m getting the following error:

Fatal error: Declaration of Shoppingcart::addToCart() must be compatible with that of Ishoppingcart::addToCart() in klassen         


        
4条回答
  •  时光取名叫无心
    2020-12-10 02:40

    The declaration of a public function in a sub class must match that of its parent:

    public function addToCart();
    public function addToCart( Product $product)
    

    You cannot add a parameter to the signature.

    This is closely related to the Liskov substitution principle.

提交回复
热议问题