Skip to content

Commit c195cfd

Browse files
committed
opcache: tests for file-scope const inlining edge cases
1 parent 35cd64d commit c195cfd

5 files changed

Lines changed: 114 additions & 0 deletions

File tree

ext/opcache/tests/pass1_const_inline_002.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ function use_global_const_fqn() {
2020

2121
class MyClass {
2222
const CLASS_CONST = 99;
23+
final const FINAL_CLASS_CONST = 77;
2324

2425
public function use_class_const() {
2526
return self::CLASS_CONST;
2627
}
28+
29+
public function use_static_class_const() {
30+
return static::CLASS_CONST;
31+
}
32+
33+
public function use_static_final_class_const() {
34+
return static::FINAL_CLASS_CONST;
35+
}
2736
}
2837

2938
function use_class_const_static() {
@@ -62,3 +71,16 @@ MyClass::use_class_const:
6271
; (after optimizer)
6372
; %s
6473
0000 RETURN int(99)
74+
75+
MyClass::use_static_class_const:
76+
; (lines=%d, args=%d, vars=%d, tmps=%d)
77+
; (after optimizer)
78+
; %s
79+
0000 T%d = FETCH_CLASS_CONSTANT (static) (exception) string("CLASS_CONST")
80+
0001 RETURN %s
81+
82+
MyClass::use_static_final_class_const:
83+
; (lines=%d, args=%d, vars=%d, tmps=%d)
84+
; (after optimizer)
85+
; %s
86+
0000 RETURN int(77)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
const EXTERNAL_CONST = 42;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
const declared only in a separate required file is not inlined by the optimizer
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable_cli=1
7+
opcache.opt_debug_level=0x20000
8+
--FILE--
9+
<?php
10+
11+
require __DIR__ . '/pass1_const_inline_005.inc';
12+
13+
function use_external_const() {
14+
return EXTERNAL_CONST;
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
$_main:
20+
; (lines=%d, args=%d, vars=%d, tmps=%d)
21+
; (after optimizer)
22+
; %s
23+
0000 INCLUDE_OR_EVAL (require) string("%s")
24+
0001 RETURN int(1)
25+
26+
use_external_const:
27+
; (lines=%d, args=%d, vars=%d, tmps=%d)
28+
; (after optimizer)
29+
; %s
30+
0000 T%d = FETCH_CONSTANT string("EXTERNAL_CONST")
31+
0001 RETURN %s
32+
33+
$_main:
34+
; (lines=%d, args=%d, vars=%d, tmps=%d)
35+
; (after optimizer)
36+
; %s
37+
0000 DECLARE_CONST string("EXTERNAL_CONST") int(42)
38+
0001 RETURN int(1)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
const SHARED_CONST = 42;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
const redeclared after being declared in a separate required file: optimizer inlines local value, runtime warning
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable_cli=1
7+
opcache.opt_debug_level=0x20000
8+
--FILE--
9+
<?php
10+
11+
require __DIR__ . '/pass1_const_inline_006.inc';
12+
13+
const SHARED_CONST = 99;
14+
15+
function use_shared_const() {
16+
return SHARED_CONST;
17+
}
18+
19+
var_dump(use_shared_const());
20+
21+
?>
22+
--EXPECTF--
23+
$_main:
24+
; (lines=%d, args=%d, vars=%d, tmps=%d)
25+
; (after optimizer)
26+
; %s
27+
0000 INCLUDE_OR_EVAL (require) string("%s")
28+
0001 DECLARE_CONST string("SHARED_CONST") int(99)
29+
0002 INIT_FCALL 1 %d string("var_dump")
30+
0003 INIT_FCALL 0 %d string("use_shared_const")
31+
0004 T%d = DO_UCALL
32+
0005 SEND_VAL T%d 1
33+
0006 DO_ICALL
34+
0007 RETURN int(1)
35+
36+
use_shared_const:
37+
; (lines=%d, args=%d, vars=%d, tmps=%d)
38+
; (after optimizer)
39+
; %s
40+
0000 RETURN int(99)
41+
42+
$_main:
43+
; (lines=%d, args=%d, vars=%d, tmps=%d)
44+
; (after optimizer)
45+
; %s
46+
0000 DECLARE_CONST string("SHARED_CONST") int(42)
47+
0001 RETURN int(1)
48+
49+
Warning: Constant SHARED_CONST already defined, this will be an error in PHP 9 in %s on line %d
50+
int(99)

0 commit comments

Comments
 (0)