Can I do this, maybe using ReflectionClass ?
myprintr($some_object);
function myprintr(){
foreach(func_get_args() as $key => $arg){
// here I want to get the name of the passed variable, "some_object"
// $key seems to be numeric...
}
}
If the user passes an object to myprintr(), then you can use
to get the name of the object type that has been passed, which you can then feed to reflection
but the reflection constructor will accept either a class name or an object as an argument, so you don’t even need the class name to instantiate a reflection class
EDIT
Just for the sake of playing a bit with this concept (and not creating any dependency on globals), or on whether the arguments are variables, values returned from functions, strings, etc:
This retrieves all the arguments passed by the calling function in $calledWithArgNames, so for the first call you have:
and for the second call:
This still requires splitting down into the individual arguments (a preg_split on commas, except where they’re inside braces), but is certainly a step closer to what you’re actually asking for.