微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以在执行PHP脚本的每一行后运行PHP函数?

我的问题与此类似: Is it possible to run code after each line in Ruby?
但是我想用PHP来做.

是否可能,如果可能,怎么样?

你可以 registertick handler

Ticks

A tick is an event that occurs for every N low-level tickable statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare blocks’s directive section.

Not all statements are tickable. Typically,condition expressions and argument expressions are not tickable.

正如您所看到的,它不完全是“每行代码”,除非您每行只写一个可选择的语句.但它是你能得到的最接近的.

例:

declare(ticks=1);
register_tick_function(function() {
    echo "tick_handler() called\n";
});

echo 'Line 1',PHP_EOL;
echo 'Line 2',PHP_EOL;
echo strtoupper('Line 3'),PHP_EOL;

输出(demo):

tick_handler() called
Line 1
tick_handler() called
Line 2
tick_handler() called
LINE 3
tick_handler() called

原文地址:https://www.jb51.cc/php/240123.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐