With the introduction of Object-Oriented and Namespacing capabilities in PHP, I am loving the new found cleanliness of PHP code that can be produced. The annoying thing though is that the core of PHP is still cluttered, unorganized mess of functions.
Are there any initiatives to organize the PHP core and "common" libraries into namespaces and classes?
Namespaces are qualifiers that solve two different problems: They allow for better organization by grouping classes that work together to perform a task. They allow the same name to be used for more than one class.
To address this problem, namespaces were introduced in PHP as of PHP 5.3. The best way to understand namespaces is by analogy to the directory structure concept in a filesystem. The directory which is used to group related files serves the purpose of a namespace.
In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions: Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
There's been some discussion, but no real will -- the PHP dev team is too short for the size of the project and there are other priorities. You should note that it that would break backwards compatibility with older scripts, even if the current global names are left as is. See here.
You might want to see the RFC that proposes the use of namespaces for internal classes and its discussion in the internals mailing list here and here.
SPL is a good start in this direction.
http://php.net/manual/en/book.spl.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With