xref: /PHP-7.4/ext/opcache/tests/bug66338.phpt (revision c0e15a3b)
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--CONFLICTS--
8server
9--FILE--
10<?php
11$root  = str_replace('.php', "", __FILE__);
12$base  = basename( $root );
13
14file_put_contents( "$root-Officials.inc", '<?php
15	class Officials { static function getLeader() { return LocalTerms::GOV_LEADER; } }
16	' );
17
18file_put_contents( "$root-clientUS.php", '<?php
19	class LocalTerms { const GOV_LEADER = "Barack Hussein Obama II"; }
20	require \''.$root.'-Officials.inc\';
21	printf( "The President of the USA is %s\n", Officials::getLeader() );
22	' );
23
24file_put_contents( "$root-clientUK.php", '<?php
25	class LocalTerms { const GOV_LEADER = "David William Donald Cameron"; }
26	require \''.$root.'-Officials.inc\';
27	printf( "The Prime Minister of the UK is %s\n", Officials::getLeader() );
28	' );
29
30include "php_cli_server.inc";
31$uri = sprintf("http://%s/%s", PHP_CLI_SERVER_ADDRESS, basename(__FILE__));
32$opt = -1;   # This test works if $opt = 0
33php_cli_server_start("-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.optimization_level=$opt -d opcache.file_update_protection=0" );
34
35echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUS.php" );
36echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$base-clientUK.php" );
37
38unlink("$root-Officials.inc");
39unlink("$root-clientUS.php");
40unlink("$root-clientUK.php");
41?>
42--EXPECT--
43The President of the USA is Barack Hussein Obama II
44The Prime Minister of the UK is David William Donald Cameron
45