|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-07 12:01 UTC] axel dot ml at warenform dot net
Description:
------------
With active opcache following problems occurs:
If constants.php is called first the output is:
1
1
1
1
1
which is correct.
If constants-include.php is called the output is:
4
which is also correct.
If constants.php is called afterwards the output is:
1
1
1
4
1
which is wrong.
The line is @define('SOME_CONSTANT', 4) is conditionally because of the "@" and must not be evaluated by opcache but on runtime.
If the line is rewritten as:
if (!defined('SOME_CONSTANT')) define('SOME_CONSTANT', 4);
everything works as expected.
Thank you for fixing this issue.
Test script:
---------------
FILE: constants-include.php
@define('SOME_CONSTANT', 4);
echo SOME_CONSTANT.'<br>'.PHP_EOL;
FILE: constants.php
define('SOME_CONSTANT', 1);
echo SOME_CONSTANT.'<br>'.PHP_EOL;
@define('SOME_CONSTANT', 2);
echo SOME_CONSTANT.'<br>'.PHP_EOL;
@define('SOME_CONSTANT', 3);
echo SOME_CONSTANT.'<br>'.PHP_EOL;
include('./constants-include.php');
echo SOME_CONSTANT.'<br>'.PHP_EOL;
Expected result:
----------------
1
1
1
1
1
Actual result:
--------------
1
1
1
4
1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 12:00:02 2025 UTC |
I experience the same issue with php 5.6.6 : myscript.php : define('FOO','hello'); include('somefile.php'); echo ANOTHER_FOO; somefile.php : define('FOO','hi'); define('ANOTHER_FOO',FOO.' world'); myscript.php prints : in PHP<5.6 : "hello world" in PHP5.6 : "hi world"This has been fixed at some point with the addition of the ZEND_OPTIMIZER_PASS_15 ("collect constants") flag, which is disabled by default.