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 ofpublic
Use
is_a( )
instead ofinstanceof
Copy an object instead of making a reference (requires
zend.ze1_compatibility_mode
to beOn
)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 usesvar
instead ofpublic
(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( ...
Get Upgrading to PHP 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.