From: jo at feuersee dot de
Operating system: Linux
PHP version: 7.0.1
Package: opcache
Bug Type: Bug
Bug description:Wrong bytecode in cache of array index named 'init' containing 0 indexed
subarr
Description:
------------
Let me first say that the test script below actually fails to reproduce
the bug. I tried the whole day to provide a simple way to reproduce the
problem, but without success.
But what happens is pretty much the execution of caller.php:
Another file is parsed via require() and assigned to a PHP variable. The
problem is that the array index named 'init' seems to be incorrectly
cached, it is still an array, but index 0 always becomes 1.
Other (scalar) entries in $conf are not affected. To add some oddness:
- Only the array index called 'init' is affected. Even 'Init' does work,
so it's pretty unlikely to happen.
- Only the subindex 0 is affected. Thus, a simple workaround this bug is
to force the array keys to start with eg. 1
- When forcing the 1st entry to have the array key of -1, the 2nd array
key (becoming the key 0 then) is affected.
The application where the bug occurs is way more complex involving ~30
files, autoloader and all the bells and whistles. I am, on the other
side, sure that it's not an application bug, but a PHP issue.
That is because:
1) The application did and does work fine with older PHP versions until
5.6.15 (incl). Did not test with PHP7.0.0
2) The problem does not occur when Zend opcache is disabled
3) After altering and saving config.php (thus forcing the opcache to
expire), the next execution will be perfectly fine. The next ones will
always fail, until the cache is invalidated again
4) I nailed this behavior down by adding the print_r call directly next
to the require call (just as in the test script), so there is no way the
app is responsible (by altering the value of 'init' keys itself.
As mentioned, AFAICS it only occurs on array keys named 'init', so it's
unlikely to happen. If it happends, the impact is sadly grave.
Test script:
---------------
config.php:
<?php
$conf['init'] = array(
"SET NAMES'utf8'",
"SHOW TABLES"
);
return $conf;
--eof
caller.php:
<?php
$conf = require 'config.php';
print_r($conf);
--eof
Expected result:
----------------
Array
(
[init] => Array
(
[0] => SET NAMES 'utf8'
[1] => SHOW TABLES
)
)
Actual result:
--------------
Array
(
[init] => Array
(
[0] => 1
[1] => SHOW TABLES
)
)
--
Edit bug report at https://bugs.php.net/bug.php?id=71261&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71261&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71261&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71261&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71261&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71261&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71261&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71261&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71261&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71261&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71261&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71261&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71261&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71261&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71261&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71261&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71261&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71261&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71261&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71261&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71261&r=mysqlcfg