如何在不构造全局变量的情况下访问函数内部的变量


How to access a variable inside a function without the construction of a global?

<?php
declare(ticks=1);
function tick_handler()
{
print($GLOBALS['a']);
}
register_tick_function('tick_handler');

function test()
{
$a = 1;//This not print
$a = 2;//This not print
$a = 3;//This not print
$a = 4;//This not print
}
test();
$a = 1;//This print
$a = 2;//This print
$a = 3;//This print
$a = 4;//This print
?>

How print//不打印,但没有全局$a ?

不带

function test()
{
$GLOBALS['a'] = 1;//This not print
$GLOBALS['a'] = 2;//This not print
$GLOBALS['a'] = 3;//This not print
$GLOBALS['a'] = 4;//This not print
}

我不是100%确定你想做什么,但是

例如,在Joomla改变标签规定的页面底部的页面底部的这个1)你必须下载主机转储脚本2)找到一块html脚本代码,是旁边3)调查函数的行为4)找到一个地方html代码教育它需要几个小时,我只是找到$globals和register_tick_function的帮助

听起来你做错了。

如果您需要调试应用程序和/或需要查看哪些函数和方法以什么顺序和使用什么参数被调用,那么请使用合适的调试器:

见https://stackoverflow.com/questions/1494288/good-free-php-debugger

谢谢,但是xdebug在hostmonster.com被禁用了

你要而不是调试你的生产站点。如果您需要添加更多特性或应用更改,请首先在开发服务器上执行这些操作。确保它能够工作,然后将更改部署到您的生产站点。因此,要么将XDebug放在本地机器上,要么放在虚拟机或类似的地方。或者为您的开发环境找一个新的主机。在任何情况下,把它放在开发和调试不会影响生产的地方。

相关文章: