Bug #77275 [NEW]: OPcache optimization problem for ArrayAccess->offsetGet(string)
| From: | kentaro at ranvis dot com | Date: | Mon, 10 Dec 2018 05:46:36 +0000 |
| Subject: | Bug #77275 [NEW]: OPcache optimization problem for ArrayAccess->offsetGet(string) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218355@lists.php.net to get a copy of this message | ||
From: kentaro at ranvis dot com
Operating system: Windows 10
PHP version: 7.3.0
Package: opcache
Bug Type: Bug
Bug description:OPcache optimization problem for ArrayAccess->offsetGet(string)
Description:
------------
In a certain condition, a call to the class method offsetGet() via
$instance['literalString'] is turned into $instance[anotherLiteral] when
OPcache is enabled.
Steps to reproduce:
1. On Windows x64, extract php-7.3.0-nts-Win32-VC15-x64.zip into the
current directory
2. Save test script as test.php
3. Make sure no PHP built-in server is running (as shared memory
matters?)
4. Launch PHP built-in server by running a command:
php -c php.ini-development -d extension_dir=ext -d
zend_extension=php_opcache.dll -S 127.0.0.1:8000
5. Open browser and go to http://127.0.0.1:8000/test.php
The output is: string(1) "a"
6. Touch test.php to update the modification time, and wait 3 seconds
(opcache.revalidate_freq)
7. Reload the browser and confirm the output
Test script:
---------------
<?php
namespace Foo;
class Bar { public function get() {} }
class Record implements \ArrayAccess {
public function offsetSet($offset, $value) { throw new \Exception;
}
public function offsetGet($offset) { var_dump($offset); }
public function offsetExists($offset) { throw new \Exception; }
public function offsetUnset($offset) { throw new \Exception; }
}
class Baz {
public function run() {
$a = pow(1, 2);
$b = new Bar();
$c = new Bar();
$d = new Bar();
$id = $b->get('a', 'b', 'c');
$rec = new Record();
$id = $rec['a'];
}
}
(new Baz())->run();
Expected result:
----------------
The output is: string(1) "a"
Actual result:
--------------
The output is: string(1) "b"
--
Edit bug report at https://bugs.php.net/bug.php?id=77275&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77275&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77275&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77275&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77275&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77275&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77275&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77275&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77275&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77275&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77275&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77275&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77275&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77275&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77275&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77275&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77275&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77275&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77275&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77275&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77275&r=mysqlcfg