The DECLARE construct is a crucial part of the structure control in PHP. The DECLARE construct is used to set the execution directives of script codes; directives set the behavior of a declare block.

There are two types directives recognized by PHP DECLARE: ticks and encoding.

Syntax for DECLARE construct

<?php
    declare (statement);
?>

Tick directive

Basic example with a DECLARE construct

<?php
    declare(ticks=1); // valid statement
    const TICK_VALUE = 1; //invalid statement
    declare(ticks=TICK_VALUE);
?>

A tick is an event that occurs number of specified low-level tick able statements executed by the parser within the declare block. The occurred events are specified by register_tick_function().

Example of a DECLARE construct with TICK directive set

Encoding directive

By using the encoding directives, a script’s encoding is specified for each script. 

Basic example of a DECLARE construct with ENCODING directive set

<?php
    declare(encoding='ISO-8859-1');
    // code here....
?>

 

›› go to examples ››