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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:41:52+00:00 2026-06-18T11:41:52+00:00

I just got stuck with the following problem. I’m trying to construct a class

  • 0

I just got stuck with the following problem. I’m trying to construct a class but it isn’t working. When I’m constructing the class it uses namespaces and variables, because the variable has to be put behind a backslash (for the namespace) it gives an error.
Here’s an example code of defining the class;

$className = 'Help';
$controller = new \controller\$className;

The class name is defined in a variable, in the example code above I’ve just set it to ‘Help’. When constructing the class it has \controller\ in front of it, that’s cause it’s in that namespace. If I remove the namespace thing away so it just has;

$controller = new $className;

it does work. The problem is probably caused because there’s a backslash in front of the variable which contains the class name to construct. I am not able to add use controller; in the beginning of the code because the file containing the class is loaded inside the constructor, and the class is immediately constructed after the file has been loaded. The use function could only be used in the beginning of your file, not inside a method, I think.

I hope someone could help me out,.

Thanks in advance,
Tim Visée

  • 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-18T11:41:53+00:00Added an answer on June 18, 2026 at 11:41 am

    Your first example is invalid syntax. You would need instead something like:

    $className = '\controller\Help';
    $controller = new $className();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck on the following problem and would like to know if you got
I was just starting having fun with haskell when I got stuck. I'm trying
I just got pagination to work on my site, but I wanted to use
I just got a job offer to be a FE Developer, but I've never
We just got our first major Perl CGI assignment in my CS class. Our
I just got the following type error while executing my Python script: File /Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py,
I'm following this railscast and got stuck immediately: http://asciicasts.com/episodes/244-gravatar Whenever I try to edit
Just got the new iPad, and when I touch the microphone and say a
i just got a call from Hosting company, they claimed that my application creates
I just got an email from twitter saying my keys have now been enabled

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.