Bug #72966 [Opn]: declare(ticks=1) doesn't seem to be impacting files included by a parent file

[email protected] ("matt dot minix at gmail dot com") Mon, 29 Aug 2016 18:17:32 GMT
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=72966&edit=1

 ID:                 72966
 User updated by:    matt dot minix at gmail dot com
 Reported by:        matt dot minix at gmail dot com
 Summary:            declare(ticks=1) doesn't seem to be impacting files
                     included by a parent file
 Status:             Open
 Type:               Bug
-Package:            Documentation problem
+Package:            PHP Language Specification
 Operating System:   CentOS Linux release 7.2.1511
 PHP Version:        7.0.10
 Block user comment: N
 Private report:     N

 New Comment:

I think I chose the wrong package for this bug


Previous Comments:
------------------------------------------------------------------------
[2016-08-29 18:13:54] matt dot minix at gmail dot com

I tested this in php 5.6.18, and it is definitely working differently in 5.6.18 than 7.0.10.  In 5.6.18 it gives the expected result of 

 tick 
 tick 
 tick 
 tick 
0 tick 
1 tick 
2 tick 
3 tick 
4 tick 
5 tick 
6 tick 
7 tick 
8 tick 
9 tick 
 tick 
 tick

------------------------------------------------------------------------
[2016-08-29 17:49:34] matt dot minix at gmail dot com

Description:
------------
---
From manual page: http://www.php.net/control-structures.declare
---

It's possible I'm making some silly mistake, but, I'm 95% sure I was able to do this in 5.x and I don't see anything saying it's been undone, and in looking to see if this report has any duplicates I came across an example of it working as I'd expect it to rather than how it currently is.  From the documentation there's

"The declare construct can also be used in the global scope, affecting all code following it (however if the file with declare was included then it does not affect the parent file)."

My interpretation of that is a parent file can for example have declare(ticks=1);  and then a file included by that file that will still have the tick function called per tick.  That does not seem to be the case at the moment, see test script below.

Test script:
---------------
Two files!  If you put everything in one file it will work as intended,  Files start.php and test.php

<- start.php ->

<?php

declare(ticks=1);
register_tick_function(function() {
    echo " tick \n";
});

require_once("test.php");

$A = new foo();
$A->bar();



<- test.php ->

<?php

class foo {
    function bar() {
        for($i = 0; $i < 10; $i++) {
	    echo $i;
	}
    }
}



Expected result:
----------------
(This is what you get if it is all in one file)

 tick 
 tick 
 tick 
0 tick 
1 tick 
2 tick 
3 tick 
4 tick 
5 tick 
6 tick 
7 tick 
8 tick 
9 tick 
 tick 
 tick 

Actual result:
--------------
 tick 
 tick 
 tick 
0123456789 tick 


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72966&edit=1