Examples of PHP declare control characters and ticks

Source: Internet
Author: User
Tags control characters

The declare structure is used to set the execution instructions for a section of code, and its syntax is structured as follows:

DECLARE (Directive)

Statement


Don't understand? The popular explanation is as follows:

The ticks parameter represents a function that runs the number of statements called once register_tick_function.
The Register_tick_function function defines the handler function at the time each tick event occurs. So what is the tick incident?

Tick is an event.

The Tick event occurs one time in PHP for each execution of n low-level statements, and n is specified by the Declare statement.
You can use Register_tick_function () to specify the action that should be taken when the tick event occurs.


The question comes again, what is the low-level statement? It includes:

Simple statements: Empty statements (just A; number), return, break, continue, throw, Goto, Global, Static, unset, ECHO, built-in HTML text, semicolon-terminated expression, etc.
Compound statement: The complete If/elseif, while, Do...while, for, foreach, switch, try...catch, etc. are counted as a statement.
Statement BLOCK: A block of statements enclosed in {}.
Finally Special: Declare block itself is also a statement (according to the reason declare block is also considered a compound statement, but here deliberately separate it out).


Look at a simple example:

The code is as follows Copy Code

/**
* DECLARE
* @link http://www.111cn.net
*/
function Do_tick ()
{
echo "<font color=red>do_tick</font>";
}

Register_tick_function (' Do_tick ');

DECLARE (ticks = 1)
{
for ($i = 1; $i < 5; $i + +)
{
echo "<font color=blue>{$i}</font><br>";
}
}


The results of the above procedure:


PHP declare control characters and ticks detailed tutorials explain the results:

The first time into the For loop, the first Do_tick function is performed after the Echo is executed;
After the first for loop ends, the second Do_tick function is executed;
Cycle four times ... ;
The fifth time for the loop, the condition is not satisfied, for the loop end, the execution of a do_tick function;
The declare itself is also a statement, and the Do_tick function is executed once.

As can be seen from the above, 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.