Skip to Main Content
Upgrading to PHP 5
book

Upgrading to PHP 5

by Adam Trachtenberg
July 2004
Intermediate to advanced content levelIntermediate to advanced
350 pages
10h 9m
English
O'Reilly Media, Inc.
Content preview from Upgrading to PHP 5

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( ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Expert PHP and MySQL®

Expert PHP and MySQL®

Andrew Curioso, Ronald Bradford, Patrick Galbraith
Pro PHP Programming

Pro PHP Programming

Peter MacIntyre, Brian Danchilla, Mladen Gogala
Mastering PHP 7

Mastering PHP 7

Branko Ajzele

Publisher Resources

ISBN: 0596006365Supplemental ContentCatalog PageErrata