From:             frank at huddler dot com
Operating system: CentOS
PHP version:      5.2.5
PHP Bug Type:     Unknown/Other Function
Bug description:  Scope of declare(ticks=1); statement is unclear

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 bug report at http://bugs.php.net/?id=44345&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44345&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44345&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44345&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44345&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44345&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44345&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44345&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44345&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44345&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44345&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44345&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44345&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44345&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44345&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44345&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44345&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44345&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44345&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44345&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44345&r=mysqlcfg

Reply via email to