The declare structure is used to set the execution instructions for a piece of code. The declare syntax is similar to other process control structures: declare (directive) statement declare structure is used to set the execution instructions of a piece of code. The declare syntax is similar to other process control structures:
declare (directive) statement
The directive section allows you to set the behavior of the declare code segment. Currently, only two commands are known: ticks and encoding.
Note: encoding is a new command for PHP 5.3.0.
The statement section in the declare code segment will be executed-how to execute and what side effects will occur depends on the instruction set in direve VE.
The declare structure can also be used in a global range, affecting all subsequent code (however, if a file with the declare structure is contained by another file, it does not work for the parent file containing it ).
Ticks
Tick (clock cycle) is an event that occurs when the interpreter executes N low-level statements that can be timed in the declare code segment. The value of N is specified by ticks = N in the directive section of declare.
Not all statements can be timing. Generally, conditional expressions and parameter expressions do not support timing.
The events that occur in each tick are specified by register_tick_function. For more details, see the example below. Note that multiple events can appear in each tick.
Example #1 Example of Tick usage
0) { $a += 2; print($a);}?>
Example #2 Ticks usage Example
0) { $a += 2; tick_handler(); print($a); tick_handler();}tick_handler();?>
See register_tick_function () and unregister_tick_function ().
Encoding
You can use the encoding command to specify the encoding method for each script.
Example #3 specify the encoding method for the script
Declare (encoding = 'ISO-8859-1 ');
// Code here
?>
When combined with a namespace, the only legal syntax of declare is declare (encoding = '...'); where... is the encoded value. And declare (encoding = '...') {} will produce a parsing error when combined with the namespace.
In PHP 5.3, unless -- enable-zend-multibyte is specified during compilation, the encoding value in declare is ignored.
Note: Unless phpinfo () is used, PHP does not show whether -- enable-zend-multibyte is specified during compilation.