The declare structure is used to set execution instructions for a piece of code. The syntax of declare is similar to other process Control structures:
DECLARE (Directive) statement
The directive section allows you to set the behavior of the declare code snippet. Currently only two commands are known: Ticks and encoding.
Note:encoding is a new directive for PHP 5.3.0.
The statement part of the declare code snippet will be executed--how and what side effects in execution depend on the instructions set in directive.
The declare structure can also be used for global scope, affecting all subsequent code (but if the file with the declare structure is contained by another file, it does not work with the parent file that contains it).
<?php//These is the same://you can use This:declare (Ticks=1) { //entire script here}//or you can use THIS:DECL Is (ticks=1);//Entire script here?>
Ticks
Tick (clock cycle) is an event that occurs in the declare code snippet when an interpreter executes an N-timed low-level statement. The value of N is specified in the directive section of declare with Ticks=n.
Not all statements can be timed. Neither the conditional expression nor the parameter expression is timed.
The events that appear in each tick are specified by Register_tick_function (). See the example below for more details. Note Multiple events can occur in each tick.
Example of usage of Example #1 Tick
<?phpdeclare (Ticks=1);//A function called on each tick eventfunction Tick_handler () { echo "Tick_handler () called \ n ";} Register_tick_function (' Tick_handler '); $a = 1;if ($a > 0) { $a + = 2; print ($a);}? >
Example #2 Ticks Examples of usage
<?phpfunction Tick_handler () { echo "Tick_handler () called\n";} $a = 1;tick_handler (), if ($a > 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 directive to specify how each script is encoded.
Example #3 specifying the encoding for a script
<?php
Declare (encoding= ' iso-8859-1 ');
code here
?>
Caution The only legal syntax for declare when combined with namespaces is declare (encoding= ' ... '); is the encoded value. The Declare (encoding= ' ... ') {} will produce a parsing error when combined with a namespace.
In PHP 5.3, the encoding value in declare is ignored unless--enable-zend-multibyte is specified at compile time.
Note that unless you use Phpinfo (), PHP does not show whether--enable-zend-multibyte is specified at compile time.