从被调用函数中获取变量名

Ale*_*lex 1 php reflection

我可以这样做,也许使用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...
  }


}
Run Code Online (Sandbox Code Playgroud)

Kar*_*ath 6

你不能得到"变量"的名称,因为没有变量.

例如:

myprintr("test");
myprintr(myotherfun());
Run Code Online (Sandbox Code Playgroud)

注意:我不确定你要做什么,但我只是觉得可怕的错误......函数和对象的重点是创建障碍,并且调用者的上下文中的内容应该无关紧要.