PHP Declare Construct

The declare construct is used to help direct some later lines of code in what to do. It can make, for example, a for loop loop through a certain number of times based on an assigned value, it can call a function multiple times based on a value, and it can encode a block of code.

Basic syntax follows:

declare (directive);
script
				

*global scope

Or:

declare (directive){
script
}
				

*local scope

There are two directives: the ticks directive and the encoding directive. The ticks are what hold a value for later use, while encoding, well, encodes what follows it with the encoding type that you specified.

The tick directive is an event that occurs as much as the value is set to. An example is shown below:

declare(ticks=5);
				

You set the tick's function with the following code:

register_tick_function('function name');
				

The set function, when called, will be executed as many times of the value of the tick, in this case five.

You can also encode script with declare by using the encoding directive:

declare(encoding="encodingtype");
				

With some newer versions of PHP, however, the encode directive may be ignored if it isn't compiled with --enable-zend-multibyte, which is able to detect if PHP is Unicode encoded.