Skip to content

Commit c141ee3

Browse files
committed
Allow arbitrary expressions in new/instanceof using () syntax
1 parent 357fbc9 commit c141ee3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
new with an arbitrary expression
3+
--FILE--
4+
<?php
5+
6+
$class = 'class';
7+
var_dump(new ('std'.$class));
8+
var_dump(new ('std'.$class)());
9+
$obj = new stdClass;
10+
var_dump($obj instanceof ('std'.$class));
11+
12+
?>
13+
--EXPECT--
14+
object(stdClass)#1 (0) {
15+
}
16+
object(stdClass)#1 (0) {
17+
}
18+
bool(true)

Zend/zend_language_parser.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ class_name:
10781078
class_name_reference:
10791079
class_name { $$ = $1; }
10801080
| new_variable { $$ = $1; }
1081+
| '(' expr ')' { $$ = $2; }
10811082
;
10821083

10831084
exit_expr:

0 commit comments

Comments
 (0)