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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:12:01+00:00 2026-05-25T11:12:01+00:00

I just recently discovered variable variables in PHP, needless to say, it´s usefulness is

  • 0

I just recently discovered variable variables in PHP, needless to say, it´s usefulness is immense:

$name = "ABC";
$$name = "DEF";
echo ${"ABC"}; //Gives: DEF

That got me thinking, which brings us to my question:

Since we can have names that´s variable, can´t we also have functions that´s variable?
Not ‘functions’ as in the names of functions, but (more or less) as in:

$func = 'function test() { echo "Success!"; }';
$func(); //If this would work, it would give: Success!

Or, even better, variables classes:

$class = 'class { function test() { echo "Success!"; } }';
$instance = new $class;
$instance->test(); //In a (not-so) perfect world this would give: Success!

Any of this possible?

  • 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-25T11:12:02+00:00Added an answer on May 25, 2026 at 11:12 am

    The only way this would work is using eval.

    $func = "echo 'Success!';";
    eval($func);
    

    You can use variables to call functions as well.

    function foo()
    {
        echo 'Success';
    }
    
    $foo = 'foo';
    $foo();
    

    Keep in mind – you’re entering a dangerous area of PHP as this usually only obfuscates your code for any future developers having to maintain your code (including yourself in a few months).

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

Sidebar

Related Questions

I've just recently updated my PHP to a newer version and have discovered that
I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as
I have just recently discovered how much I enjoy developing code the TDD way:
I have just recently discovered the difference between different constructors in GDI+. Going: var
I've just recently discovered the power of jQuery. Just a quick question though. What
I'm a fairly experienced programmer and I've just recently discovered node.js. I love JavaScript
I'm quite new here, and just recently discovered jQuery. I have a list: <ul
I recently discovered that Delphi has a global variable called ReportMemoryLeaksOnShutdown, when set to
i'm a newbie to jquery... i just recently discovered the jquery UI library. what
Learning perl I just recently discovered the wonders of Moose! I'm trying to wrap

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.