B.2 New E_STRICT Error Setting

PHP 5's new E_STRICT error setting issues a warning when you use deprecated features. Specifically, it complains when you:

  • Create objects without a class definition

  • Use a constructor named after the class instead of _ _construct( )

  • Use var instead of public

  • Use is_a( ) instead of instanceof

  • Copy an object instead of making a reference (requires zend.ze1_compatibility_mode to be On)

  • Statically invoke a nonstatic method

  • Refine the prototype of an inherited method other than _ _construct( )

  • Return a nonvariable by reference

  • Assign the object returned by new by reference

All of these features work in PHP 5, but you should slowly modify your code to stop using them. Here are a few examples:

  • This code automagically creates $person as an object without a class definition:

    $person->name = 'Rasmus Lerdorf';
    PHP Strict Standards:  Creating default object from empty value

  • This Person class uses var instead of public (or, even better, private). It also defines two constructors:

    class Person {
        var $name;
        function _ _construct($name) {
            $this->name = $name;
        function Person($name) {
            $this->name = $name;   
    PHP Strict Standards:  var: Deprecated. Please use the public/private/protected modifiers
    PHP Strict Standards:  Redefining already defined constructor for class Person

E_STRICT is not enabled by default, nor is it part of E_ALL. To enable it, set your error_reporting configuration directive to E_ALL | E_STRICT. Setting E_STRICT within a PHP script using error_reporting( ) causes PHP to miss some errors because it has already parsed the file.