Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:28:20+00:00 2026-05-15T16:28:20+00:00

As far as I can tell, the only reason we have namespacing in PHP

  • 0

As far as I can tell, the only reason we have namespacing in PHP is to fix the problem of classes (+ functions & constants) clashing with others classes of the same name.

The problem is that most frameworks setup their autoload and filesystem hierarchy to reflect the names of the classes. And no-one actually require()s or include()s files anymore.

So how does namespacing help this any? Either the class is loaded based off of it’s name:

new Zend_Db_Table_Rowset_Abstract;

or off it’s namespace

new Zend\Db\Table\Rowset\Abstract;

Either way I am stuck with only being able to create one class with this name.

/var/www/public/Zend/Db/Table/Rowset/Abstract.php

UPDATE
I’m not sure I’m getting the point across.

Even if I created two files with the same class Zend\Db\Table\Rowset\Abstract in them I still couldn’t use them together since they both claim the same namespace. I would have to change their namespace names which is what we already do!

This leaves me to belive that the only use for namespaces is function names. Now we can finally have three functions all named the same thing!

Or wait, I forgot you can’t do that either since each requires the namespace prefix!

a\myfunction();
b\myfunction();
c\myfunction();

Taking ircmaxell’s example:

$model = new \Application\Model\User;
$controller = new \Application\Controller\User;

How is that any different than without?

$model = new Application_Model_User;
$controller = new Application_Controller_User;

This is also a neat sounding feature – but what does it truly do for us?

use \Application\Model\User as UserModel;
use \Application\Controller\User as UserController;

$foo = new UserModel;
$bar = new UserController;

Now you cannot have a class named ‘UserModel’ since you have a namespace setting for that term. You also still cannot have two classes named under the same alias.

I guess the good thing is that you can rename the long Zend_Db_Table_Rowset_Abstract

use Zend_Db_Table_Rowset_Abstract as RowAbstract;

leading to developer confusion about where the non-existent class “RowAbstract” is defined and coming from in the system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:28:21+00:00Added an answer on May 15, 2026 at 4:28 pm

    My impression is that namespaces are used in a cargo cult programming fashion. Because it’s new, it gets used like crazy. Deeply nested namespaces, like in Doctrine2, add no further protection against name conflicts. And it’s very obvious that \nested\name\spaces are just used to achieve a 1:1 mapping to directory/file names. Clearly a code smell.

    But I suppose this phenomenon is also caused by trying to mimick Java module names in PHP. And furthermore the backslash syntax doesn’t convey a sensible semantic as in other languages.

    Anyway, the ability to rename classes while importing namespaces is a big bon. That’s useful when it actually comes to mixing conflicting definitions. And the namespace syntax can simply be added, once an actual name conflict arises. (I see no need to implement namespaces right away, when name conflicts are that rare and for most projects a purely fictional problem.)
    If you do it only when required, the awkward namespace syntax never even has to rear its ugly head. If there is only one namespace level to import, you can just use namespace1\Class as LocalName and don’t convolute the application with any namespace1\Class syntax. (Still it’s a better idea not to use overly generic class names in namespaces.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this trigger which works functionally (as far as I can tell by
As far as I can tell the only way to convert from BitmapSource to
As far as I can tell this only affects IE 8. Using the following
As far as I can tell, this is isn't possible, so I'm really just
As far as I can tell, the best way to do this is do
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell, this code is fine, and should display some
As far as I can tell I wouldn't think it would make any difference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.