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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:03:53+00:00 2026-06-14T13:03:53+00:00

In PHP, I can access a function in global namespace from another namespace using

  • 0

In PHP, I can access a function in global namespace from another namespace using myFunc(), instead of \myFunc(). PHP Will automatically fallback to the global namespace, if myFunc cannot be resolved in the current namespace.

Which is the recommended way? \myFunc() or myFunc()?

  • 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-06-14T13:03:54+00:00Added an answer on June 14, 2026 at 1:03 pm

    Second option is better if you want to implement some kind of polymorphism or to completely change function’s logic. Something like this.

    namespace Nkamm;
    
    // like a PHP6
    function strstr($needle, $haystack)
    {
        return \strstr($haystack, $needle);
    }
    
    var_dump(strstr('t', 'Long test'));
    

    Result:

    string(4) "test"
    

    But I would not like to do such “overloads” because that will cause the mess (until they are strictly documented in project). Hence there is no sense to overwrite existing functions.

    Summing up: keep your functions in your namespace, use global functions without any backslashes.

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

Sidebar

Related Questions

In php how can I access an array's values without using square brackets around
How can i block all access to a php file using mod_sec? The file
I would like to access a MySQL database using PHP. Can someone please explain
How can I generate graphs and charts from a mysql database using php? I'm
How can I access function b from within function a? This is what I
I can not access the global variable in function in included file sample files
In PHP you can access both the names and values of an array in
In config/routes.php <?php return array( 'account/profile/change_password' => 'users/account/change_password', ); I can access site.com/users/account/change_password and
How can I access a static variable in a separate class in PHP? Is
In PHP I can use a foreach loop such that I have access to

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.