dongxian3574 2013-12-05 03:54
浏览 53

什么是PHP中的低级别可选语句

PHP version:5.3.3

Here is the example:

<?php
    declare(ticks=1);
    // declare(ticks=2);
    function handler()
    {
        echo "handler called
";
    }
    register_tick_function('handler');
    $a = 1;
    // Output: handler called
handler called
 
?>

The Output is the same handler called handler called whenever assign the var ticks as 1 or 2.

Below is the opcode generated by 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.

**In php manual,it says:

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.**

But in the example script, The output is the same whenever assign ticks as 1 or 2

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题