Skip to content

Commit 8333a54

Browse files
committed
Implement variable and constant pinning
This is basically free.
1 parent 249c88c commit 8333a54

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Pinning pattern
3+
--FILE--
4+
<?php
5+
6+
$a = 1;
7+
$b = '1';
8+
$c = 'foo';
9+
10+
var_dump(1 is ^$a);
11+
var_dump(2 is ^$a);
12+
var_dump(1 is ^$b);
13+
var_dump('foo' is ^$c);
14+
var_dump('bar' is ^$c);
15+
var_dump('1' is ^$a);
16+
17+
const A = 1;
18+
const B = '1';
19+
const C = 'foo';
20+
21+
var_dump(1 is ^A);
22+
var_dump(2 is ^A);
23+
var_dump(1 is ^B);
24+
var_dump('foo' is ^C);
25+
var_dump('bar' is ^C);
26+
var_dump('1' is ^A);
27+
28+
?>
29+
--EXPECT--
30+
bool(true)
31+
bool(false)
32+
bool(false)
33+
bool(true)
34+
bool(false)
35+
bool(false)
36+
bool(true)
37+
bool(false)
38+
bool(false)
39+
bool(true)
40+
bool(false)
41+
bool(false)

Zend/zend_language_parser.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@ pattern:
14121412

14131413
atomic_pattern:
14141414
scalar_pattern { $$ = zend_ast_create(ZEND_AST_EXPR_LIKE_PATTERN, $1); }
1415+
| '^' T_VARIABLE { $$ = zend_ast_create(ZEND_AST_EXPR_LIKE_PATTERN, zend_ast_create(ZEND_AST_VAR, $2)); }
1416+
| '^' constant { $$ = zend_ast_create(ZEND_AST_EXPR_LIKE_PATTERN, $2); }
14151417
| type_pattern { $$ = $1; }
14161418
| object_pattern { $$ = $1; }
14171419
| array_pattern { $$ = $1; }

0 commit comments

Comments
 (0)