Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initiatives to namespace PHP core and libraries

Tags:

php

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?

like image 300
James Maroney Avatar asked May 23 '10 17:05

James Maroney


People also ask

What is the purpose of namespace in PHP?

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.

What is the best approach for working with classes and namespaces in PHP?

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.

Does PHP support 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.

What is the point of namespaces?

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.


2 Answers

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.

like image 174
Artefacto Avatar answered Nov 15 '22 09:11

Artefacto


SPL is a good start in this direction.

http://php.net/manual/en/book.spl.php

like image 41
VladFr Avatar answered Nov 15 '22 09:11

VladFr