PHP » PYTHON |
login |
register |
about
|
|
declareThe declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs:
declare (directive)
statement
The directive section allows the behavior of the declare block to be set. Currently only two directives are recognized: the ticks directive (See below for more information on the ticks directive) and the encoding directive (See below for more information on the encoding directive).
The statement part of the declare block will be executed - how it is executed and what side effects occur during execution may depend on the directive set in the directive block. The declare construct can also be used in the global scope, affecting all code following it (however if the file with declare was included then it does not affect the parent file).
<?php
TicksCaution
As of PHP 5.3.0 ticks are deprecated and will be removed in PHP 6.0.0. A tick is an event that occurs for every
N low-level statements executed
by the parser within the declare block.
The value for N is specified
using The event(s) that occur on each tick are specified using the register_tick_function(). See the example below for more details. Note that more than one event can occur for each tick.
Example #1 Profile a section of PHP code
<?phpThe example profiles the PHP code within the 'declare' block, recording the time at which every second low-level statement in the block was executed. This information can then be used to find the slow areas within particular segments of code. This process can be performed using other methods: using ticks is more convenient and easier to implement. Ticks are well suited for debugging, implementing simple multitasking, background I/O and many other tasks. See also register_tick_function() and unregister_tick_function(). EncodingA script's encoding can be specified per-script using the encoding directive. Example #2 Declaring an encoding for the script.
<?php
Caution
When combined with namespaces, the only legal syntax for declare is declare(encoding='...'); where ... is the encoding value. declare(encoding='...') {} will result in a parse error when combined with namespaces. The encoding declare value is ignored in PHP 5.3 unless php is compiled with --enable-zend-multibyte. In PHP 6.0, the encoding directive will be used to inform the scanner what encoding the file is created in. Legal values are encoding names such as UTF-8. |
more
Recently updated
more
Most requested
more
Last requests
|