#44345 [Opn->Csd]: Scope of declare(ticks=1); statement is unclear

From: Date: Fri, 07 Nov 2008 11:26:53 +0000
Subject: #44345 [Opn->Csd]: Scope of declare(ticks=1); statement is unclear
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1424@lists.php.net to get a copy of this message
ID: 44345 Updated by: vrana@php.net Reported By: frank at huddler dot com -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: CentOS PHP Version: 5.2.5 New Comment: 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)" Previous Comments: ------------------------------------------------------------------------ [2008-03-05 22:49:32] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44345&edit=1

« previous php.doc.bugs (#1424) next »