PHP版本:5.3.3
以下是示例:
<?php
declare(ticks=1);
// declare(ticks=2);
function handler()
{
echo "handler called\n";
}
register_tick_function('handler');
$a = 1;
// Output: handler called\nhandler called\n
?>
只要将var handler called\nhandler called\n
指定为ticks
或1
,输出就会相同2
。
以下是vld生成的操作码:
Finding entry points
Branch analysis from position: 0
Return found
filename: /home/soooldier/Php/2.php
function name: (null)
number of ops: 10
compiled vars: !0 = $a
line # * op fetch ext return operands
---------------------------------------------------------------------------------
2 0 > TICKS 1
1 TICKS 1
4 2 NOP
7 3 TICKS 1
8 4 SEND_VAL 'handler'
5 DO_FCALL 1 'register_tick_function'
6 TICKS 1
9 7 ASSIGN !0, 1
8 TICKS 1
10 9 > RETURN 1
branch: # 0; line: 2- 10; sop: 0; eop: 9
path #1: 0,
Function handler:
Finding entry points
Branch analysis from position: 0
Return found
filename: /home/soooldier/Php/2.php
function name: handler
number of ops: 3
compiled vars: none
line # * op fetch ext return operands
---------------------------------------------------------------------------------
6 0 > ECHO 'handler+called%0A'
1 TICKS 1
7 2 > RETURN null
branch: # 0; line: 6- 7; sop: 0; eop: 2
path #1: 0,
End of function handler.
**在php manual中,它说:
tick是由声明块内的解析器执行的每N个低级别可选语句发生的事件。在声明块的指令部分中使用ticks = N指定N的值。**
但是在示例脚本中,只要将ticks
指定为1
或2