PHP 5.3 is no longer a news and it is written about him decently (and he somehow became boring after the release of version 5.4). Nevertheless, I would like to focus on one of its features.
One of the most striking features of this version is the support of namespaces, which resulted in a change in the PHP programming paradigm. Accordingly, many, eminent and not very, frameworks began to rewrite their code in a new way. This article is just about what it all led to.
A small example *:
')
\\index.php namespace Zend\Date { function is_object($date) { echo "Zend Date constructor is called with param {$date}";exit; } } namespace Foo { require_once 'zf2/library/Zend/Loader/AutoloaderFactory.php'; \Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => array())); $date = new \Zend\Date\Date('2012-03-18'); }
What's going on here? I redefined the is_object function which is called at the very beginning of the \ Zend \ Date \ Date constructor. If you change the definition of a function so that the value is passed by reference, then you can change not only the result, but also the parameters themselves that are passed to the function.
This code works because php is by default, looking for a function in the declared namespace, and only if it is not there, goes to search in the global namespace. And we can declare neymspeysy with the same name anywhere and as many times as you like. By the way, with the constants the same story.
This feature provides tremendous opportunities for debugging and testing (goodbye runkit), but also opens a huge security hole in the application.
If you think that this feature is a problem for your code, you can avoid it simply by adding backslash (\) to the function call (constant). Then PHP will immediately search for a definition in the global namespace.
In conclusion, I want to say that at the moment you can do such things in Zend, Symfony, Doctrine.
* - interpreter version 5.4.0RC9-dev
UPD:
FAQ: things you need to know about namespaces