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 - January 5th, 2010 at 17:31

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

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

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

(will not be published)
  1. No trackbacks yet.