ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾PHP ±à³Ì£¾PHP 5 Power programming
Team LiB
Previous Section Next Section

13.9. Summary

This chapter highlights some changes in PHP 5 that affect scripts written and working under PHP 4. A new object model and new OO features in PHP 5 mean that some OO scripts written for PHP 4 won't run correctly with PHP 5. If you cast an object to an int, the result is always 1, rather than 0 as in PHP 4. When you compare objects in PHP 5, true is returned only if the objects are the same, with the same object handle. The PHP 5 behavior for these three changes can be reverted to PHP 4 behavior by turning on Zend 1 compatibility mode in the php.ini file. However, two other changes cannot be reverted. In PHP 5, you can no longer assign an object to $this inside a class. In addition, the get_class() function in PHP 5 returns the class name with its upper- and lowercase characters preserved. As well as changes, some features are deprecated. A new error typeE_STRICTwarns you when you use deprecated features, as long as you specify E_STRICT errors in the php.ini file. Although PHP still allows the automatic creation of objects of class StdClass by assigning a value to a property, you get an E_STRICT error when you do this. Also, the var designation for properties is deprecated in favor of public. In addition, a new constructorconstruct()is introduced with PHP 5. PHP 5 throws an E_STRICT error when it encounters a function in an inherited class with a different signature than a function of the same name in the parent class.

As well as OO changes, a few other changes break backward compatibility. When setting up PHP on Windows, the names and locations some of the files in the distribution have changed. For instance, the CGI binary is now called php-cgi.exe rather than php.exe. The parser changed the way it tokenizes comments. MySQL is no longer enabled by default and the client library is no longer bundled, so you need to use an external library. The array_merge() function no longer accepts a non-array parameter, and strrpos() and strripos() now use the full $needle to search for a substring in a string. There are many other changes, including additional features for functions and new functions, but most changes do not affect existing scripts that run with PHP 4.

    Team LiB
    Previous Section Next Section