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.

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

// the following function is called on each tick event
function w3r_tick()
echo "w3r_tick() called<br>";
$a = 5;
if ($a > 0)
$a += 2;

View the example in the browser

Previous: switch statement
Next: return statement

PHP: Tips of the Day

PHP: How to fix error with xml2-config not found when installing PHP from sources?

All you need to do instal install package libxml2-dev for example:

sudo apt-get install libxml2-dev


sudo yum install libxml2-devel

Ref : https://bit.ly/34hOrfG