mirror of
https://github.com/php/php-src.git
synced 2024-11-30 21:35:36 +08:00
Fix ?-> in encaps vars without braces
Closes GH-5966.
This commit is contained in:
parent
898bb97706
commit
10f660f0a5
@ -19,6 +19,15 @@ var_dump(null?->baz);
|
||||
var_dump(null?->qux());
|
||||
var_dump(null?->quux());
|
||||
|
||||
var_dump($foo?->bar);
|
||||
var_dump($foo?->baz);
|
||||
var_dump($foo?->qux());
|
||||
try {
|
||||
var_dump($foo?->quux());
|
||||
} catch (Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
var_dump((new Foo)?->bar);
|
||||
var_dump((new Foo)?->baz);
|
||||
var_dump((new Foo)?->qux());
|
||||
@ -28,20 +37,6 @@ try {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
var_dump("{$null?->foo}");
|
||||
var_dump("{$null?->bar}");
|
||||
var_dump("{$null?->qux()}");
|
||||
var_dump("{$null?->quux()}");
|
||||
|
||||
var_dump("{$foo?->bar}");
|
||||
var_dump("{$foo?->baz}");
|
||||
var_dump("{$foo?->qux()}");
|
||||
try {
|
||||
var_dump("{$foo?->quux()}");
|
||||
} catch (Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
NULL
|
||||
@ -54,13 +49,9 @@ Warning: Undefined property: Foo::$baz in %s.php on line 20
|
||||
NULL
|
||||
string(3) "qux"
|
||||
string(36) "Call to undefined method Foo::quux()"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(3) "bar"
|
||||
|
||||
Warning: Undefined property: Foo::$baz in %s.php on line 34
|
||||
string(0) ""
|
||||
Warning: Undefined property: Foo::$baz in %s.php on line 29
|
||||
NULL
|
||||
string(3) "qux"
|
||||
string(36) "Call to undefined method Foo::quux()"
|
||||
|
61
Zend/tests/nullsafe_operator/033.phpt
Normal file
61
Zend/tests/nullsafe_operator/033.phpt
Normal file
@ -0,0 +1,61 @@
|
||||
--TEST--
|
||||
Test nullsafe operator in encaps vars
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Foo {
|
||||
public $bar = 'bar';
|
||||
|
||||
function qux() {
|
||||
return 'qux';
|
||||
}
|
||||
}
|
||||
|
||||
$null = null;
|
||||
$foo = new Foo();
|
||||
|
||||
var_dump("{$null?->foo}");
|
||||
var_dump("{$null?->bar()}");
|
||||
var_dump("$null?->foo");
|
||||
var_dump("$null?->bar()");
|
||||
|
||||
var_dump("{$foo?->bar}");
|
||||
var_dump("{$foo?->baz}");
|
||||
var_dump("{$foo?->qux()}");
|
||||
try {
|
||||
var_dump("{$foo?->quux()}");
|
||||
} catch (Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
var_dump("$foo?->bar");
|
||||
var_dump("$foo?->baz");
|
||||
var_dump("$foo?->qux()");
|
||||
try {
|
||||
var_dump("$foo?->quux()");
|
||||
} catch (Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(2) "()"
|
||||
string(3) "bar"
|
||||
|
||||
Warning: Undefined property: Foo::$baz in %s.php on line 20
|
||||
string(0) ""
|
||||
string(3) "qux"
|
||||
string(36) "Call to undefined method Foo::quux()"
|
||||
string(3) "bar"
|
||||
|
||||
Warning: Undefined property: Foo::$baz in %s.php on line 29
|
||||
string(0) ""
|
||||
|
||||
Warning: Undefined property: Foo::$qux in %s.php on line 30
|
||||
string(2) "()"
|
||||
|
||||
Warning: Undefined property: Foo::$quux in %s.php on line 32
|
||||
string(2) "()"
|
@ -2257,8 +2257,8 @@ inline_char_handler:
|
||||
}
|
||||
|
||||
|
||||
/* Make sure a label character follows "->", otherwise there is no property
|
||||
* and "->" will be taken literally
|
||||
/* Make sure a label character follows "->" or "?->", otherwise there is no property
|
||||
* and "->"/"?->" will be taken literally
|
||||
*/
|
||||
<ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE>"$"{LABEL}"->"[a-zA-Z_\x80-\xff] {
|
||||
yyless(yyleng - 3);
|
||||
@ -2266,6 +2266,12 @@ inline_char_handler:
|
||||
RETURN_TOKEN_WITH_STR(T_VARIABLE, 1);
|
||||
}
|
||||
|
||||
<ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE>"$"{LABEL}"?->"[a-zA-Z_\x80-\xff] {
|
||||
yyless(yyleng - 4);
|
||||
yy_push_state(ST_LOOKING_FOR_PROPERTY);
|
||||
RETURN_TOKEN_WITH_STR(T_VARIABLE, 1);
|
||||
}
|
||||
|
||||
/* A [ always designates a variable offset, regardless of what follows
|
||||
*/
|
||||
<ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE>"$"{LABEL}"[" {
|
||||
|
Loading…
Reference in New Issue
Block a user