PHPdeclare console and ticks

Source: Internet
Author: User
The declare structure is used to set the execution command of a piece of code. Its syntax structure is as follows: declare (directive) & amp; nbsp; statement doesn't understand? The general explanation is as follows: Decia

The declare structure is used to set the execution command of a piece of code. Its syntax structure is as follows:

Declare (directive)
Statement

Don't you understand? The general explanation is as follows: declare is the PHP process control structure. directive currently supports two commands [ticks and encoding]. the use of ticks must be used with the register_tick_function function (of course, the unregister_tick_function function. The ticks parameter indicates how many statements are run to call the register_tick_function function once.
The register_tick_function function defines the processing function for each tick event. So what is a tick event?
  • Tick is an event.
  • The tick event occurs once every time N low-level statements are executed in PHP, and N is specified by the declare statement.
  • You can use register_tick_function () to specify the operations that should be performed when a tick event occurs.

The problem arises again. what is a low-level statement? It includes:
  • Simple statement: empty statement (just one; number), return, break, continue, throw, goto, global, static, unset, echo, built-in HTML text, A semicolon-terminated expression is considered as a statement.
  • Composite statement: The Complete if/elseif, while, do... while, for, foreach, switch, try... catch and so on are regarded as a statement.
  • Statement block.
  • The last note is that the declare block itself is also a statement (in principle, the declare block is also a composite statement, but it is specially isolated here ).

Let's look at a simple example:
/** * declare * @link http://www.phpddt.com */function do_tick(){        echo "do_tick";}register_tick_function('do_tick');declare(ticks = 1){        for($i = 1; $i < 5; $i++)        {                echo "{$i}
"; }}

The running result of the above program:
Explain the result as follows:
  1. Enter the for loop for the first time, execute echo and then execute the do_tick function for the first time;
  2. After the first for loop ends, execute the second do_tick function;
  3. Loop four times ......;
  4. The fifth for loop is performed. if the condition is not met, the for loop ends and the do_tick function is executed;
  5. Declare itself is also a statement and also needs to execute the do_tick function once.

As shown in the preceding figure, declare and ticks can be used for debugging or performance testing.

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.