What’s new in PHP 5.3?
With last week's announcement of RC4, the final release of PHP 5.3 is imminent. So what can we expect in this version? Here I'll outline the biggest and most interesting changes and additions. This is definitely not exhaustive since there are tons of minor changes and improvements in this version, but these are some of the ones I found interesting.
Namespaces
Namespaces are a way to separate classes and functions to avoid naming collisions. Using namespaces prevents problems with using classes with the same name but different functionality. You can declare a namespace using the namespace keyword. You can also use the use keyword to set the namespace for all future calls to classes or functions without specifying the path each time.
MySQL Native Driver
PHP 5.3 comes with a native MySQL driver designed specifically for PHP called mysqlnd, replacing the external libmysql driver. This should increase performance with MySQL functions.
PHP Manual on the MySQL Native Driver
Class Constants
It is now possible to declare constants within the context of a class. You declare constants the same way you declare normal variables, except you use the const keyword.
Late Static Bindings
Late static binding causes static calls to methods within a class to use the latest version of that method if it was overridden. To use this, you use the static keyword instead of self. It's best shown as an example, which you can find at the link below.
PHP Manual on Late Static Bindings
The goto Operator
An interesting addition to the PHP language is the goto operator, which allows you to jump to a named section of you code to start executing. You name a section with a label followed by a colon (section:) and you move to it using goto followed by the label (goto section;). This might be useful in some very strange circumstances, but it should probably be avoided.
Other Points of Interest
- Native support for the math functions:
asinh(),acosh(),atanh(),log1p(), andexpm1() - Pixelation support using the GD
imagefilter()function - Blowfish and extended DES support for
crypt() - Deprecated all
ereg_functions (use PCREpreg_functions instead) - SQLite3 support
- Several new classes and methods
- Much more...
For more information about the upgrade to PHP 5.3, see the upgrade notes.
Similar Posts:
- Snippet: Autoloading Objects (PHP 5)
- Using a PHP Class to Store Configuration
- Create Callbacks Using __invoke
