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)');
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…