Is there a way to get the name of a variable? PHP - Reflection

前端 未结 11 615
旧巷少年郎
旧巷少年郎 2020-12-15 08:50

I know this is not exactly reflection, but kind of. I want to make a debug function that gets a variable and prints a var_dump and the variable name.

Of course, when

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 09:20

    I believe Alix and nickf are suggesting this:

    function debug($variablename)
    {
      echo ($variablename . ":
    "); global $$variablename; // enable scope var_dump($$variablename); }

    I have tested it and it seems to work just as well as Wagger's code (Thanks Wagger: I have tried so many times to write this and the global variable declaration was my stumbling block)

提交回复
热议问题