3.7. Declare

The declare statement marks a block of code for execution under a set of conditions. Figure 3.8 shows the form of a declare statement.

Figure 3.8. The declare statement.
						declare(directive)
{
    Zero or more statements
}

At the time of writing, PHP accepts only one directive: ticks. The ticks directive paired with the register_tick_function cause PHP to pause execution of a script periodically to execute a function. Each tick represents a lowest-level event determined by the parser. This functionality is not meant for general programming, and PHP does not guarantee any matching between the number of ticks and the number of statements inside the declare block. Listing 3.14 shows an example of a registered tick function.

Listing 3.14. ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.