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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:39:05+00:00 2026-05-18T19:39:05+00:00

Wondering if anyone else has encountered this problem when utilizing the new ability to

  • 0

Wondering if anyone else has encountered this problem when utilizing the new ability to namespace classes using PHP 5.3.

I am generating a dynamic class call utilizing a separate class for defining user types in my application. Basically the class definer takes an integer representation of types and interprets them, returning a string containing the classname to be called as the model for that user.

I have an object model for the user’s type with that name defined in the global scope, but I have another object with the same name for the user’s editor in the Editor namespace. For some reason, PHP won’t allow me to make a namespaced dynamic call as follows.

$definition = Definer::defineProfile($_SESSION['user']->UserType);
new \Editor\$definition();

The identical syntax works for calling the global basic object model in the global namespace and I use it this way reliably throughout the application.

$definition = Definer::defineProfile($_SESSION['user']->UserType);
new $definition();

This will correctly call the dynamically desired class.

Is there a reason the two would behave differently, or has dynamic calling for namespaces not been implemented in this manor yet as this is a new feature? Is there another way to dynamically call a class from another namespace without explicitly placing its name in the code, but from within a variable?

  • 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-18T19:39:06+00:00Added an answer on May 18, 2026 at 7:39 pm

    Well, just spell out the namespace in the string:

    $definition = Definer::defineProfile($_SESSION['user']->UserType);
    $class = '\\Editor\\' . $definition;
    $foo = new $class();
    

    And if it’s a child namespace (as indicated in the comments), simply prepend the namespace with __NAMESPACE__:

    $class = __NAMESPACE__ . '\\Editor\\' . $definition;
    

    So if the current namespace is \Foo\Bar, and $definition is “Baz”, the resulting class would be \Foo\Bar\Editor\Baz

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

Sidebar

Related Questions

Just wondering if anyone else has spotted this: On some user's machines running our
I was wondering if anyone else has tried to develop a PHP extension that
was wondering if there are anyone else here that has signed up with the
Im wondering if anyone has any input on this subject? Im building a flash
I'm wondering if anyone else has experienced the following issue. On a single non-linked
I was just wondering if anyone else just sees integration tests as just a
Wondering if anyone has gotten the infamous database is locked error from Trac and
Wondering if anyone can help me with this annoying but trivial (in terms of
Just wondering if anyone has any favourite SQL references they to use when creating
I was wondering if anyone knew of any limitations to using Windows XP as

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.