如何在不构建全局变量的情况下访问函数内部的变量?
<?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
?>
如何打印 //这不是打印,而是没有全局 $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
}
<?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 //This not print ,but without global $a ?
And without
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 确定你想做什么,但是
听起来像你做错了。
如果您需要调试应用程序和/或需要查看以什么顺序和使用什么参数调用哪些函数和方法,请使用适当的调试器:
请参阅https://stackoverflow.com/questions/1494288/good-free-php-debugger
您不想想要调试您的生产站点。如果您需要添加更多功能或应用更改,请先在开发服务器上执行此操作。确保它有效,然后将更改部署到您的生产站点。因此,要么将 XDebug 放在本地计算机上,要么放入虚拟机或类似的东西中。或者为您的开发环境寻找一个新的托管服务商。无论如何,将其放置在开发和调试不会中断生产的地方。
I am not 100% sure what you are trying to do but
sounds like you-are-doing-it-wrong.
If you need to debug your application and/or need to see which functions and methods got called in what order and with what parameters, then use a proper debugger:
See https://stackoverflow.com/questions/1494288/good-free-php-debugger
You do not want to debug your production site. If you need to add more features or apply changes, do so on your development server first. Make sure it works, then deploy the changes to your production site. So either put XDebug on your local machine or into a VM or anything like that. Or get a new hoster for your development environment. In any case, put it where development and debugging wont disrupt production.