Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are namespaces bad for performance? (PHP)

Tags:

php

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)?

like image 516
Tudor Avatar asked Feb 07 '12 14:02

Tudor


People also ask

Are PHP namespaces case sensitive?

Note: Namespace names are case-insensitive.

Why namespaces are needed 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.

Can we use two namespaces in PHP?

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.

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. All identifiers at namespace scope are visible to one another without qualification.


1 Answers

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

like image 194
Garry Welding Avatar answered Sep 20 '22 13:09

Garry Welding