Skip to content

Commit 017a213

Browse files
committed
Test nullsafe in new
1 parent f81ed70 commit 017a213

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Zend/tests/nullsafe_operator/019.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test nullsafe in new
3+
--FILE--
4+
<?php
5+
6+
class Bar {}
7+
8+
class Foo {
9+
public $bar;
10+
}
11+
12+
$foo = new Foo();
13+
$foo->bar = 'bar';
14+
var_dump(new $foo?->bar);
15+
16+
$foo = null;
17+
var_dump(new $foo?->bar);
18+
19+
?>
20+
--EXPECTF--
21+
object(Bar)#2 (0) {
22+
}
23+
24+
Fatal error: Uncaught Error: Class name must be a valid object or a string in %s.php:14
25+
Stack trace:
26+
#0 {main}
27+
thrown in %s.php on line 14

Zend/zend_language_parser.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,8 @@ new_variable:
13011301
{ $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
13021302
| new_variable T_OBJECT_OPERATOR property_name
13031303
{ $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
1304+
| new_variable T_NULLSAFE_OBJECT_OPERATOR property_name
1305+
{ $$ = zend_ast_create(ZEND_AST_NULLSAFE_PROP, $1, $3); }
13041306
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
13051307
{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
13061308
| new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable

0 commit comments

Comments
 (0)