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

  • Home
  • SEARCH
  • 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 6381071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:20:58+00:00 2026-05-25T02:20:58+00:00

I have a few general use functions that do not really make sense in

  • 0

I have a few general use functions that do not really make sense in any class as static methods. I would like to encapsulate them under a namespace so there are no conflicts with functions defined in the global scope. For my namespaced classes, I follow the widely-adopted pattern where a class such as \My\Namespaced\MyClass exists in My/Namespaced/MyClass.php on the include path.

Is there a best practice for where namespaced functions should be placed? Right now I’m putting them in “functions.php” within the directory holding classes under the same namespace. For example \My\Namespaced\myFunction exists in My/Namespaced/functions.php.

Also, is there any way to autoload these functions in the same way that classes are autoloaded?

  • 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-25T02:20:58+00:00Added an answer on May 25, 2026 at 2:20 am

    Also, is there any way to autoload these functions in the same way that classes are autoloaded?

    Not for global functions, but if …

    Is there a best practice for where namespaced functions should be placed?

    I would consider using objects instead a “best practice”, however we all know that it’s not totally true.

    There is no autoloading for global functions, you can encapsulate functions into classes as static functions and then the autoloader will kick into action. So that might be a suggestion, however you should be clear about the implications those static functions have for your overall design.

    So to say: If you’re okay with global functions, then you might be okay with global static class functions. They will break if you change a class’s name (like with any global function name), you have however created something that can autoload and is compatible with your file naming scheme.

    Edit: When I write global, I mean the fully qualified name of a function, that’s the one starting with \. See Name resolution rules Docs.

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

Sidebar

Related Questions

Quick question. What do you think, I have a few sites that use a
In general, I occasionally have a chain of nested macros with a few preprocessor
I have few Question for which I am not able to get a proper
In almost all of my projects I have few files that are project wide
I'm currently working on a C++ project that needs to have as few external
I just have a few general questions about keeping code clean and readable. 1)
I'm taking a cloud computing course and have a few problems that I am
Suppose I have an interface that supports a few potential operations: interface Frobnicator {
I have recently learned that you can use a neat switch statement with fallthrough
I have few asynchronous tasks running and I need to wait until at least

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.