简体   繁体   English

如何在当前范围内转储所有PHP变量?

[英]How can i dump all PHP variables in current scope?

I need this for debugging purposes and need to dump all variables. 我需要此用于调试目的,并且需要转储所有变量。 Is there a way to get all variables? 有没有办法获取所有变量? and is there any way to trace all calls after script ends? 脚本结束后有什么方法可以跟踪所有调用? without changing my code. 无需更改我的代码。 Note that i can't use xdebug or anything installable because my script is runnign on a host. 请注意,我无法使用xdebug或任何可安装的东西,因为我的脚本在主机上运行。

Check out the get_defined_vars function within PHP. 查看PHP中的get_defined_vars函数。

This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called. 此函数返回一个多维数组,该数组包含在调用get_defined_vars()范围内的所有已定义变量的列表,这些变量是环境变量,服务器变量或用户定义的变量。

You can try using get_defined_vars . 您可以尝试使用get_defined_vars

<?php
    $a = 12;
    $b = "foo";
    $bar = "test";

    echo '<pre>';
    print_r(get_defined_vars());
?>

http://codepad.viper-7.com/UI38ud http://codepad.viper-7.com/UI38ud

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM