I've made some changes for a php framework to suport namespaces and the result wasn't as expected. For a simple test (mostly framework classes loaded) the execution time slowed down with ~10%.
From your experience, is it worth it to use namespaces on large apps (considering the actual development level of PHP)?
Note: Namespace names are case-insensitive.
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.
Multiple namespaces may also be declared in the same file. There are two allowed syntaxes. This syntax is not recommended for combining namespaces into a single file. Instead it is recommended to use the alternate bracketed syntax.
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. All identifiers at namespace scope are visible to one another without qualification.
The accepted answer on php namespace benchmark is a good way of looking at this.
I would use namespaces in pretty much any OO application I write in PHP now, it saves a lot of headaches (especially in larger projects) with clashing names. You just need to be aware of the limitations of namespaces in PHP.
http://www.php.net/manual/en/language.namespaces.faq.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