PHP Declare Statement

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP Declare Statement


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


declare (directive) statement

The following table describes two directives currently supported.




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.


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

  1. declare(ticks=5);  

  2. // the following function is called on each tick event  

  3. function w3r_tick()  

  4. {  

  5. echo "w3r_tick() called

  6. }  

  7. register_tick_function('w3r_tick');  

  8. $a = 5;  

  9. if ($a > 0)  

  10. {  

  11. $a += 2;  

  12. print($a);  

  13. }  

  14. ?>