Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Keyword enddeclare

Terminate a colon-style declare block.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

declare(ticks=1): /* statements */ enddeclare;

Terminate a colon-style declare block. Here ticks enables callbacks for tickable statements inside that region; not every PHP expression counts as a tick. Ending the block restores the enclosing directive scope. strict_types is file-wide and cannot use the block form.

$ticks=0; $cb=function() use (&$ticks){++$ticks;}; register_tick_function($cb);
declare(ticks=1): $a=1; $a++; enddeclare;
unregister_tick_function($cb); echo json_encode([$a,$ticks>0]);
[2,true]

Examples

<?php
$ticks=0; $cb=function() use (&$ticks){++$ticks;}; register_tick_function($cb);
declare(ticks=1): $a=1; $a++; enddeclare;
unregister_tick_function($cb); echo json_encode([$a,$ticks>0]);

Result

[2,true]

Sources