Skip to content

Commit a00e7f2

Browse files
committed
Fixed bug #66338 (Optimization binding of class constants is not safely opcacheable)
1 parent fff72bc commit a00e7f2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

ext/opcache/Optimizer/pass1_5.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
274274
Z_STRVAL(op_array->literals[opline->op1.constant + 1].constant),
275275
Z_STRLEN(op_array->literals[opline->op1.constant].constant) + 1,
276276
Z_HASH_P(&op_array->literals[opline->op1.constant + 1].constant),
277-
(void **)&pce) == FAILURE) {
277+
(void **)&pce) == FAILURE ||
278+
((*pce)->type == ZEND_INTERNAL_CLASS &&
279+
(*pce)->info.internal.module->type != MODULE_PERSISTENT) ||
280+
((*pce)->type == ZEND_USER_CLASS &&
281+
ZEND_CE_FILENAME(*pce) != op_array->filename)) {
278282
break;
279283
}
280284
}

ext/opcache/tests/bug66338.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #66338 (Optimization binding of class constants is not safely opcacheable)
3+
--INI--
4+
opcache.enable=0
5+
--SKIPIF--
6+
<?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?>
7+
--FILE--
8+
<?php
9+
$root = str_replace('.php', "", __FILE__);
10+
$base = basename( $root );
11+
12+
file_put_contents( "$root-Officials.inc", '<?php
13+
class Officials { static function getLeader() { return LocalTerms::GOV_LEADER; } }
14+
' );
15+
16+
file_put_contents( "$root-clientUS.php", '<?php
17+
class LocalTerms { const GOV_LEADER = "Barack Hussein Obama II"; }
18+
require "'.$root.'-Officials.inc";
19+
printf( "The President of the USA is %s\n", Officials::getLeader() );
20+
' );
21+
22+
file_put_contents( "$root-clientUK.php", '<?php
23+
class LocalTerms { const GOV_LEADER = "David William Donald Cameron"; }
24+
require "'.$root.'-Officials.inc";
25+
printf( "The Prime Minister of the UK is %s\n", Officials::getLeader() );
26+
' );
27+
28+
include "php_cli_server.inc";
29+
$uri = sprintf("http://%s/%s", PHP_CLI_SERVER_ADDRESS, basename(__FILE__));
30+
$opt = -1; # This test works if $opt = 0
31+
php_cli_server_start("-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.optimization_level=$opt -d opcache.file_update_protection=0" );
32+
33+
echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUS.php" );
34+
echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUK.php" );
35+
36+
unlink("$root-Officials.inc");
37+
unlink("$root-clientUS.php");
38+
unlink("$root-clientUK.php");
39+
?>
40+
--EXPECT--
41+
The President of the USA is Barack Hussein Obama II
42+
The Prime Minister of the UK is David William Donald Cameron

0 commit comments

Comments
 (0)