Bug #66251 [Asn->Csd]: Constants get statically bound at compile time when Optimized

From: Date: Tue, 10 Dec 2013 13:08:10 +0000
Subject: Bug #66251 [Asn->Csd]: Constants get statically bound at compile time when Optimized
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183224@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66251&edit=1 ID: 66251 Updated by: dmitry@php.net Reported by: Terry at ellisons dot org dot uk Summary: Constants get statically bound at compile time when Optimized -Status: Assigned +Status: Closed Type: Bug Package: opcache Operating System: N/A PHP Version: master-Git-2013-12-09 (Git) Assigned To: dmitry Block user comment: N Private report: N New Comment: Automatic comment on behalf of dmitry@zend.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9 Log: Fixed bug #66251 (Constants get statically bound at compile time when Optimized) Previous Comments: ------------------------------------------------------------------------ [2013-12-10 11:45:22] dmitry@php.net Yeah, it's a problem because script may behave differently with opcache enabled. We may limit constants evaluation with more strict guards (e.g. if there is a function call before constant decalarations) and/or introduce an opcache ini option that may disable/enable this optimization. ------------------------------------------------------------------------ [2013-12-10 10:15:58] Terry at ellisons dot org dot uk Xinchen, I've tabled the simplest test case which shows this bug. It shows that 5.6 executor instead of evaluating constants at runtime when the DECLARE_CONSTANT instruction is executed, you are now evaluating the constant during the compile when the const statement is parsed. Whether or not you feel that this is the wrong usage it is how 5.3.x, 5.4.x and 5.5.x do it. 5.6 doesn't. This is a fundamental B/C break. It also breaks opcachability. Where it will hit real apps is where this practice is embedded in a compiled script, because the next execution might have defined the constant differently prior to the compile, for example USERS_LANGUAGE. I can add more test scripts which look more "real world", but this is the simplest one that I could find that shows the bug. ------------------------------------------------------------------------ [2013-12-10 09:11:32] laruence@php.net the previous is a wrong usage... so I think the current opt is okey... thanks ------------------------------------------------------------------------ [2013-12-10 01:48:42] Terry at ellisons dot org dot uk Description: ------------ The B/C behaviour is to bind constants at execution of the DEFINE_CONSTANT opcode. The 5.6 optimizer now attempts to evaluate them at compile time, which changes the execution behaviour. Test script: --------------- --TEST-- Terry_001 Constants get statically bound at compile time when Optimized --INI-- opcache.enable=1 opcache.enable_cli=1 opcache.optimization_level=-1 --SKIPIF-- <?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?> --FILE-- <?php printf ("A=%s\n", getA()); const A="hello"; function getA() {return A;} --CLEAN-- --EXPECTF-- Notice: Use of undefined constant A - assumed 'A' in %son line %d A=A ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66251&edit=1

« previous php.bugs (#183224) next »