|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-11-07 11:26 UTC] vrana@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 22:00:01 2025 UTC |
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