gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:16:48 26 4
gpt4 key购买 nike

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

这可能吗?如果可能,怎么做?

最佳答案

您可以 register一个tick 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

关于php - 是否可以在执行 PHP 脚本的每一行后运行 PHP 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6214981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com