Skip to content

Commit

Permalink
Test nullsafe in new
Browse files Browse the repository at this point in the history
  • Loading branch information
iluuu1994 committed Jul 2, 2020
1 parent f81ed70 commit 017a213
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Zend/tests/nullsafe_operator/019.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Test nullsafe in new
--FILE--
<?php

class Bar {}

class Foo {
public $bar;
}

$foo = new Foo();
$foo->bar = 'bar';
var_dump(new $foo?->bar);

$foo = null;
var_dump(new $foo?->bar);

?>
--EXPECTF--
object(Bar)#2 (0) {
}

Fatal error: Uncaught Error: Class name must be a valid object or a string in %s.php:14
Stack trace:
#0 {main}
thrown in %s.php on line 14
2 changes: 2 additions & 0 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,8 @@ new_variable:
{ $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
| new_variable T_OBJECT_OPERATOR property_name
{ $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
| new_variable T_NULLSAFE_OBJECT_OPERATOR property_name
{ $$ = zend_ast_create(ZEND_AST_NULLSAFE_PROP, $1, $3); }
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
| new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable
Expand Down

0 comments on commit 017a213

Please sign in to comment.