PHP Programming with E_STRICT beware!


I recently switched to programming PHP with error_reporting set to E_STRICT, since I want to know what’s going on. You have to watch out when extending classes and trying to overrule the parameters of the child method. An example:

php-e-strict-errors

When executing you will get the following error “Strict Standards: Declaration of B::test() should be compatible with that of A::test() in /path/to/file/test.php on line 18

When I remove the parameter ‘value’ from the method ‘test’ in the class ‘B’, everything’s fine. Write that down.

, , ,

  1. #1 by Hugo on January 5, 2010 - 17:31

    and if you set the ‘value’ parameter to a default value, does it give an error too?

  2. #2 by Erik Bauffman on January 5, 2010 - 20:34

    You either have to add the parameter $value in class A or remove it from class B.

  3. #3 by simonly on November 18, 2010 - 13:34

    remove class B

(will not be published)