php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72966 declare(ticks=1) doesn't seem to be impacting files included by a parent file
Submitted: 2016-08-29 17:49 UTC Modified: 2017-03-14 13:04 UTC
Votes:9
Avg. Score:4.2 ± 0.4
Reproduced:9 of 9 (100.0%)
Same Version:6 (66.7%)
Same OS:3 (33.3%)
From: matt dot minix at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.10 OS: CentOS Linux release 7.2.1511
Private report: No CVE-ID: None
 [2016-08-29 17:49 UTC] 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 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-29 18:13 UTC] 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 18:17 UTC] matt dot minix at gmail dot com
-Package: Documentation problem +Package: PHP Language Specification
 [2016-08-29 18:17 UTC] matt dot minix at gmail dot com
I think I chose the wrong package for this bug
 [2016-08-29 19:59 UTC] stas@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-08-30 10:45 UTC] rowan dot collins at gmail dot com
This has definitely changed behaviour in PHP 7: https://3v4l.org/LsanG

And placing all the code in one file does indeed show the expected output: https://3v4l.org/8I083
 [2017-03-14 12:44 UTC] dasteph at gmail dot com
I can confirm this bug for PHP 7.1.2-4+deb.sury.org~xenial+1 on Ubuntu 16.04.2 LTS
 [2017-03-14 13:04 UTC] nikic@php.net
Duplicate of bug #71448.
 [2017-03-14 13:04 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC