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 7564613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:56:51+00:00 2026-05-30T13:56:51+00:00

After doing some research about namespacing in PHP I’m trying to figure out what

  • 0

After doing some research about namespacing in PHP I’m trying to figure out what are the real benefits other than having library items grouped together and re-use of the same class name.

What I don’t like about namespaces are these extra lines at the top of the file you’re calling the classes from ‘use core\whatever\class’, which you don’t have to do with the standard approach.

Also – something I couldn’t find information about – what happens in the situation where we need to use two classes with the same name, but in the different folders, which contain the same method name? We would still have to call the namespace, but how would the code figure out which method from which class should be used?

I’ve just started with namespaces so excuse me if this question seem to sound very basic.

Also – how does it work with the static methods – things like Helper class for instance – do I also have to indicate that I need this namespace ‘use core\whatever\Helper’ ?

  • 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-30T13:56:52+00:00Added an answer on May 30, 2026 at 1:56 pm

    If you have a large project with many classes, you’ll eventually run into naming conflicts. You have a db/mysql/adapter.php and a http/curl/adapter.php. To deal with this without namespaces, you have to give your classes unique names like Db_Mysql_Adapter and Http_Curl_Adapter, and any time you refer to these classes you need to use their full name.

    Namespaces allow you to name your classes Db\Mysql\Adapter and Http\Curl\Adapter and refer to them simply by Adapter in their local namespace, or Mysql\Adapter and Curl\Adapter respectively in other namespaces. This can save a lot of typing.

    Just browse through the source of Zend Framework version 1 vs. version 2 to see the difference.

    what happens in the situation where we need to use two classes with the same name, but in the different folders, which contain the same method name? We would still have to call the namespace, but how would the code figure out which method from which class should be used?

    If you’re in namespace Db\Mysql, Adapter::foo() refers to Db\Mysql\Adapter and \Http\Curl\Adapter::foo() would refer to the other one. You can also alias the class at the top of your file, if you don’t want to write out the whole name all the time:

    namespace Db\Mysql;
    use Http\Curl\Adapter as HAdapter;
    
    Adapter::foo();  // Mysql adapter
    HAdapter::foo(); // Http adapter, same as:
    \Http\Curl\Adapter::foo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing some research, I learned about the postfix notation, and how to parse
After doing some research and reading information about OpenCV object detection, I am still
I have the following after doing some research on other questions: MyServiceHost: public class
After doing some research on the subject, I've been experimenting a lot with patterns
After doing some research, it would seem that errno 150 occurs when either table
After doing some initial research into using Appfabric for caching, my understanding is that
I have been doing some research about this and have found a few similar
I need some functionality in an ASP.NET MVC application and after doing some research,
I've got a Java/Flex project that I'm building using Maven. After doing some research
After doing some research here, and using Google I'm still confused as to why

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.