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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:47:47+00:00 2026-05-18T23:47:47+00:00

I asked a question yesterday about namespaces that got answered, and so I tarried

  • 0

I asked a question yesterday about namespaces that got answered, and so I tarried along. The further I get into this thing though, the more I realize, I would really like to be able to generate namespaces on the fly. Reason being, I have a plugins directory where all the files get included. If someone from my company is making a plugin….or a third-party, I don’t want them to have to bother with the namespaces. I would like to just generate the namespaces on the fly by directory structure. You say, “why not just do that!” Well, I did, but I realize I still have the potential problem of classes being named the same thing and namespaces would solve this problem. Packages would solve this problem also, but I can’t find that php supports them.

-plugin
    -tabs
      +tabs.php
    -package
        -tabs
            +tabs.php

The idea is to be able to access the classes by $tabs->func() and $package_tabs->func();

Again, that is not problem, except for the darn possibility of classes being named the same thing.

I have a workaround, but if anyone know of a workaround for dynamically creating namespaces on the fly, it would interesting to hear.

The one problem I see is that PHP creates the namespace at “compile” time. So using something like fsocks to pass in a namespace was a failed attempt.

  • 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-18T23:47:48+00:00Added an answer on May 18, 2026 at 11:47 pm

    It’s not possible to do dynamically. As you mention, PHP expands the framework at compile time, so nothing in PHP itself can modify that.

    Now, you could build a program to “install” these scripts by traversing the directory structure and checking for namespaces. And if it doesn’t find one, automatically edit the file and add the namespace definition at the top. But beware that this will be problematic since any classes that are used will likely not be fully qualified (and hence throw errors at compile time).

    So the best way would just be to develop the classes with the namespaces from the beginning. It’s not that hard to do, and could be documented easily…

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

Sidebar

Related Questions

I asked a question yesterday about a click to reveal menu which got answered
This question is about a similar javascript scope problem that I asked yesterday .
I asked a question about bigints yesterday which was kindly answered. However, I have
I asked a question about different testing frameworks yesterday. This question can be found
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked this question yesterday about storing a plot within an object. I tried
Yesterday my friend asked me a question about this query: select * from user
This problem is related to This question I asked yesterday. Now it seems that
I asked a question yesterday about a problem that Im having with a program
I asked a question about initializing a 2 dimensional array yesterday, this is the

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.