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

From: Date: Tue, 14 Mar 2017 12:44:17 +0000
Subject: Bug #72966 [Com]: declare(ticks=1) doesn't seem to be impacting files included by a parent file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207825@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72966&edit=1 ID: 72966 Comment by: dasteph 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: Scripting Engine problem Operating System: CentOS Linux release 7.2.1511 PHP Version: 7.0.10 Block user comment: N Private report: N New Comment: I can confirm this bug for PHP 7.1.2-4+deb.sury.org~xenial+1 on Ubuntu 16.04.2 LTS Previous Comments: ------------------------------------------------------------------------ [2016-08-30 10:45:27] 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 ------------------------------------------------------------------------ [2016-08-29 18:17:31] matt dot minix at gmail dot com I think I chose the wrong package for this bug ------------------------------------------------------------------------ [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

« previous php.bugs (#207825) next »