Re: Namespaces in PHP5, removed?

From: Alex Farran (alex_at_alexfarran.com)
Date: 02/07/04


Date: Sat, 07 Feb 2004 20:27:12 +0000

Chung Leong writes:

> Personally, I never liked namespace. Its need is understandable in C++,
> where you link in binary libraries and there's no other workaround for name
> collisions. With PHP you can just rename the class/function.

You mean search and replace for every occurance of the duplicate
class? It's feasible, but not always very practical, and you need to
know that a name collision exists to begin with. The best practical
alternative to namespaces is a class naming convention, and that has
its own problems.

> And namespace promotes bloated class libraries, which affects
> runtime performance in PHP. When the number of classes is large
> enough where name collision is an issue, you scripts are probably
> all crawling.

Only if you include them all at once. You could have a vast library
of classes available, but only include the ones you need as you need
them. Or leave it to the optimiser to cache your classes. For PHP to
be taken seriously as an enterprise programming language, it must be
possible to write large systems in it. Namespaces make large systems
easier to write.

Apart from name collision prevention, namespaces also provide another
scope for class member access. Classes in the same namespace can
access each others members, but deny access to classes outside the
namespace. Without namespaces you must declare such members public
and hope for the best.

-- 
    __o    Alex Farran
  _`\<,_   Analyst / Programmer
 (_)/ (_)  www.alexfarran.com


Relevant Pages

  • Re: PHP6 - Comments?
    ... >> For version 6, namespaces are becoming a topic again, since the sheer ... >> number of PHP projects will surely lead to name collisions. ... namespace collision is not a problem PHP ... > programmers' tendency to write rubbish documentation. ...
    (comp.lang.php)
  • Re: PHP6 - Comments?
    ... > For version 6, namespaces are becoming a topic again, since the sheer ... > number of PHP projects will surely lead to name collisions. ... required for that request, so how many times would you want to link to TWO ... Multiple inheritance does not exist in Java, so why should it exist in PHP? ...
    (comp.lang.php)
  • Re: [PHP] circular dependency between libraries
    ... problems and leave you with only the 'slightly' inelegant situation where you ... have to, internally, sync the 2 codebases now and again. ... If PHP had namespaces, I'd be happy. ...
    (php.general)
  • Browser Cache and PHP Namespace
    ... I had some problems with broser caching behaviors and php name space ... collision. ... Is there any suggestion to avoid these kind of collisions. ...
    (php.general)
  • Re: [PHP] for the sake of conversation - syntax
    ... How does PHP work out where these "packages" are? ... The ability to have multiple namespaces per file leads to issues with the "as" or "into" syntax. ... private DbHandlerB $dbb = new DbHandlerB; ... One would hope that when namespaces are ubiquitous there will be no need to prefix functions with package identifiers. ...
    (php.general)