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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:30:52+00:00 2026-05-29T17:30:52+00:00

Fairly hard to formulate it right, so I’ll show an example I want to

  • 0

Fairly hard to formulate it right, so I’ll show an example I want to achieve:

$x = 'one';
$y = 123123;

$z = foo(bar($x, $y));
// $z = 'bar(one, 123123)'

Basically, I want this magic foo function to expand every variable to it’s value, but the function to stay as a string. What’s the best way to do this? Is it possible to do this without extracting the variables with str_replace and similar? How can we interpret the function as a string?
The requirements are that the function should be called like above, and not like a string:
foo('bar($x, $y)');

  • 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-29T17:30:59+00:00Added an answer on May 29, 2026 at 5:30 pm

    I think you can’t do it this way.

    When foo() enters into play, it receives the results of bar() already processed. Therefore, it has no access to the environment that generated them (i.e. the name of the function bar() or its paramerers). If you wished to use this foo() on generic functions, then I believe that it is not possible.

    You could do something like passing the arguments (‘bar’, $x and $y) to foo, which would become a variable-arguments function, and have this new foo() call your ‘bar’ (the first argument passed as string, which would be the name of the function). But you may have performance penalties, plus you could have problems with variables scoping…

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

Sidebar

Related Questions

This is going to be fairly hard to explain, so I've put together a
This was a fairly hard bug to find in my code but once i
I'm sure this is fairly easy, but I've kind of had a hard time
I'm fairly new to Zend and I think this question won't be so hard
This is a little bit of a hard problem to explain, so ill show
Fairly simple; I'm just curious if there's a better way to accomplish this. Given
fairly simple question and I haven't seen anything asked with this exact scenario laid
I know iPhone development fairly well. From personal experience, how hard would it be
I am fairly familiar with Autofac and one feature that I really love about
I have a fairly complex Django project which makes it hard/impossible to use fixtures

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.