Php -- declare statement

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.