declare
declare
The declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs:
Syntax:
declare (directive)
statement
The directive section allows the behavior of the declare block to be set. Currently only one directive is recognized: the ticks directive. The statement part of the declare block will be executed — how it is executed and what side effects occur during execution may depend on the directive set in the directive block.
The declare construct can also be used in the global scope, affecting all code following it.
Ticks
A tick is an event that occurs for every N low-level 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.
The event(s) that occur on each tick are specified using the register_tick_function(). Note that more than one event can occur for each tick.
Example:
<?
function profile($dump = FALSE)
{
static $profile=0;
echo $profile;
echo “<br>”;
$profile++;
}
// Set up a tick handler
register_tick_function(”profile”);
// Initialize the function before the declare block
profile();
// Run a block of code, throw a tick every 2nd statement
declare(ticks=2) {
$s=1;
$s=2;
$s=3;
}
?>
here, the function profile call explicitly one time, and it displays 0, and then it call twice by using declare statement. i.e for every 2nd statment of declare block the function profile() is called. The output is shown below
0
1
2
