xref: /PHP-7.3/ext/opcache/tests/bug66338.phpt (revision f738abab)
1--TEST--
2Bug #66338 (Optimization binding of class constants is not safely opcacheable)
3--INI--
4opcache.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
12file_put_contents( "$root-Officials.inc", '<?php
13	class Officials { static function getLeader() { return LocalTerms::GOV_LEADER; } }
14	' );
15
16file_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
22file_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
28include "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
31php_cli_server_start("-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.optimization_level=$opt -d opcache.file_update_protection=0" );
32
33echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUS.php" );
34echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUK.php" );
35
36unlink("$root-Officials.inc");
37unlink("$root-clientUS.php");
38unlink("$root-clientUK.php");
39?>
40--EXPECT--
41The President of the USA is Barack Hussein Obama II
42The Prime Minister of the UK is David William Donald Cameron
43