开发者

How do I see **all** the currently defined variables in PHP?

I need a way to see all the defined variables of the current PHP instance.

By currently defined I mean 开发者_如何学Pythonall the globals, all the local to THIS scope and all the locals to other scopes.

Is there something built in?


For everything in the current scope:

print_r(get_defined_vars());

I don't think there is a solution to dump all variables from all scopes, because you would have to actually run those functions/methods to get a complete and intact map of all available variables (variables could get created, added and removed at runtime).

You may have to look into Unit Testing or code coverage tools to see whether you can use anything from those areas, but it's going to be a lot of work.

What do you need this for?


var_dump($GLOBALS);

If a variable is not defined at the time this statement runs, then it is impossible to talk about it as having a value. Variables in "other" scopes don't exist.

{
    $a = new myClass();
    do stuff
    $a->destroy();
}
print "$a has no meaning in this context";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜