w3resource

PHP Declare Statement

Description

In PHP declare construct is used to set execution directives for a block of code. At present two directives are recognized ticks and encoding.

Syntax:

declare (directive) statement 

The following table describes two directives currently supported.

Directive Description
ticks A tick is an event. While the format of specifying the tick directive is tick=N, where N is an integer. The tick event occurs for every N statements (following the declare). Usually, condition expressions and argument expressions are excluded from being executed. Register_tick_function() is used to specify each event(s) that occur on each tick. Remember that this directive is deprecated in PHP5.3.
encoding The encoding directive specifies a script's encoding. Usage of this detective is decal re(encoding="EncodingType") where EncodingType is a encoding type like ISO-8859-1. This directive can be used only if PHP is compiled with --enable-zend-multibyte. You can use phpinfo() to know whether a PHP installation

Example of PHP declare statement using tick directive

<?php
declare(ticks=5);
// the following function is called on each tick event
function w3r_tick()
{
echo "w3r_tick() called<br>";
}
register_tick_function('w3r_tick');
$a = 5;
if ($a > 0)
{
$a += 2;
print($a);
}
?>

View the example in the browser

Previous: switch statement
Next: return statement



Follow us on Facebook and Twitter for latest update.