php一些平时没 用到的函数

来源:互联网 发布:java培训免费试听 编辑:程序博客网 时间:2024/05/15 06:51

<?php

declare(ticks=1);

// A function called on each tick event
function tick_handler()
{
     echo 
"tick_handler() called/n";
}

register_tick_function('tick_handler');

$a 1;

if (
$a 0) {
      
$a += 2;
      print(
$a);
}

?>

 

这里的register_tick_function用来注册函数,declare(ticks=1);指定没执行1条低级语句,就执行被注册的函数。

 

为了看它的底层代码,运行如下命令:


$php -r "var_dump( token_get_all(file_get_contents('test.php')) );" 

 

 

输出片段如下:

 

……

 

[2]=>

  array(3) {

    [0]=>

    int(333)   // token 号

    [1]=>

    string(8) "function"  // 字符串

    [2]=>

    int(3) //第几行

  }

……

 

可以通过以下命令,查看token的名称:

 

$php -r 'echo token_name(367);' //T_OPEN_TAG

 

 

原创粉丝点击