Skip to content
Advertisement

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

I’m getting the following error:

JavaScript

What could be the problem? I can’t find it script:

JavaScript

Advertisement

Answer

Ishoppingcart::addToCart() states that the method does not take any parameter, while the implementation Shoppingcart::addToCart(Product $product) requires that a parameter of type Product must be passed into the method. This means that both declarations are incompatible and while the implemented interface must be satisfied PHP throws the shown error.

Solution would be to either change Ishoppingcart::addToCart() to Ishoppingcart::addToCart(Product $product) so that it requires a parameter of type Product or to change Shoppingcart::addToCart(Product $product) to allow no parameter to passed into the method: Shoppingcart::addToCart(Product $product = null);

The correct way depends on your application requirements.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement