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

前端之家收集整理的这篇文章主要介绍了是否可以在执行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.f2er.com/php/240123.html

猜你在找的PHP相关文章