declare

The declare statement is used to temporarily change the state of the parser in a block of code. Here's how it looks:


function tick()
{
    static $i;
    printf("[tick i=%d]\n", ++$i);
}

register_tick_function("tick");

declare (ticks = 2) {
    1; 2; 3;
}

This example shows the only implemented parser parameter today: ticks. A tick is an event that occurs for every N low-level statements executed by the parser, where N is specified in the declare statement. The example above will print: [tick i=1] [tick i=2]

Ticks is well suited for implementing simple multitasking, backgrounded IO and many other things in PHP.

See also register_tick_function() and unregister_tick_function().


HIVE: All information for read only. Please respect copyright!
Hosted by hive КГБ: Киевская городская библиотека