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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:48:49+00:00 2026-05-16T01:48:49+00:00

What are PHP Namespaces? What are Namespaces in general? A Layman answer with an

  • 0

What are PHP Namespaces?

What are Namespaces in general?

A Layman answer with an example would be great.

  • 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-16T01:48:50+00:00Added an answer on May 16, 2026 at 1:48 am

    Namespacing does for functions and classes what scope does for variables. It allows you to use the same function or class name in different parts of the same program without causing a name collision.

    In simple terms, think of a namespace as a person’s surname. If there are two people named “John” you can use their surnames to tell them apart.

    The Scenario

    Suppose you write an application that uses a function named output(). Your output() function takes all of the HTML code on your page and sends it to the user.

    Later on your application gets bigger and you want to add new features. You add a library that allows you to generate RSS feeds. This library also uses a function named output() to output the final feed.

    When you call output(), how does PHP know whether to use your output() function or the RSS library’s output() function? It doesn’t. Unless you’re using namespaces.

    Example

    How do we solve having two output() functions? Simple. We stick each output() function in its own namespace.

    That would look something like this:

    namespace MyProject;
    
    function output() {
        # Output HTML page
        echo 'HTML!';
    }
    
    namespace RSSLibrary;
    
    function output(){
        # Output RSS feed
        echo 'RSS!';
    }
    

    Later when we want to use the different functions, we’d use:

    \MyProject\output();
    \RSSLibrary\output();
    

    Or we can declare that we’re in one of the namespaces and then we can just call that namespace’s output():

    namespace MyProject;
    
    output(); # Output HTML page
    \RSSLibrary\output();
    

    No Namespaces?

    If we didn’t have namespaces we’d have to (potentially) change a lot of code any time we added a library, or come up with tedious prefixes to make our function names unique. With namespaces, we can avoid the headache of naming collisions when mixing third-party code with our own projects.

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

Sidebar

Related Questions

I'm learning about namespaces in PHP 5.3 and I would like to use Namespaces
I have recently learnt about namespaces in PHP, and was wondering, would it be
Is it possible to get a list of all imported classes/namespaces in a PHP
So I was reading about PHP namespaces, and I realized that in versions earlier
I was just learning aboutt PHP namespaces and starting to create a simple autoload
im now using namespaces in PHP 5.3 now there is a fallback mechanism for
So far, I've seen many different naming conventions used for PHP namespaces. Some people
I know that Namespaces in PHP are relatively new and so there are many
I'm using namespaces in PHP for the first time in an application that provides
Namespaces are really useful and PHP had no support for them until the recent

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.