php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #44345 Scope of declare(ticks=1); statement is unclear
Submitted: 2008-03-05 22:49 UTC Modified: 2008-11-07 11:26 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: frank at huddler dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.5 OS: CentOS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: frank at huddler dot com
New email:
PHP Version: OS:

 

 [2008-03-05 22:49 UTC] frank at huddler dot com
Description:
------------
If you include a file with the statement:
declare(ticks=1);

It applies only to that file, and any other files included after it.  It does *not* apply to the including file.  This is not made totally clear in the documentation for declare(), which only states: "The declare construct can also be used in the global scope, affecting all code following it."

I would argue that it's reasonable to assume that 'all code following it' would include code following the include() directive; however, from experience, that isn't the case.



Even if this is by design, the documentation should more clearly state that "all code following it" actually means "all code in the file in which the declare() is invoked, and all files included after it" -- and *not* any code in the file that includes the file that invokes declare().

Reproduce code:
---------------
parent.php:
<?php
function noop() {
        echo "no-op\n";
}

include('tick.php');

while(true) {
        echo "Sleeping 1 second\n";
        noop();
        sleep(1);
}
?>

tick.php:
<?php
declare(ticks=1);
register_tick_function('tick');

function tick() {
        echo "tick\n";
}

?>

Expected result:
----------------
Sleeping 1 second
no-op
tick
Sleeping 1 second
no-op
tick
Sleeping 1 second
no-op
tick


Actual result:
--------------
Sleeping 1 second
no-op
Sleeping 1 second
no-op
Sleeping 1 second
no-op


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-07 11:26 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"(however if the file with declare was included then it does not affect the parent file)"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 28 18:00:03 2025 UTC