Bug #66251 [Asn]: Constants get statically bound at compile time when Optimized
| From: | Terry at ellisons dot org dot uk | Date: | Tue, 10 Dec 2013 10:15:59 +0000 |
| Subject: | Bug #66251 [Asn]: Constants get statically bound at compile time when Optimized | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183218@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
User updated by: Terry at ellisons dot org dot uk
Reported by: Terry at ellisons dot org dot uk
Summary: Constants get statically bound at compile time when
Optimized
Status: Assigned
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:
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.
Previous Comments:
------------------------------------------------------------------------
[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