mirror of
https://github.com/php/php-src.git
synced 2024-11-30 21:35:36 +08:00
Add tests for nullsafe operator on delayed oplines
This commit is contained in:
parent
4163923e83
commit
70300f6c9d
28
Zend/tests/nullsafe_operator/034.phpt
Normal file
28
Zend/tests/nullsafe_operator/034.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Test nullsafe operator on delayed dim
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$arr = [
|
||||
'foo' => null,
|
||||
'bar' => [
|
||||
'baz' => null,
|
||||
],
|
||||
];
|
||||
|
||||
var_dump($arr['foo']?->something);
|
||||
var_dump($arr['invalid']?->something);
|
||||
|
||||
var_dump($arr['bar']['baz']?->something);
|
||||
var_dump($arr['bar']['invalid']?->something);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
NULL
|
||||
|
||||
Warning: Undefined array key "invalid" in %s.php on line 11
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Warning: Undefined array key "invalid" in %s.php on line 14
|
||||
NULL
|
27
Zend/tests/nullsafe_operator/035.phpt
Normal file
27
Zend/tests/nullsafe_operator/035.phpt
Normal file
@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
Test nullsafe operator on delayed var
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Foo {
|
||||
public ?Bar $bar;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
public string $baz;
|
||||
}
|
||||
|
||||
$foo = new Foo();
|
||||
|
||||
$foo->bar = null;
|
||||
var_dump($foo->bar?->baz);
|
||||
|
||||
$bar = new Bar();
|
||||
$bar->baz = 'baz';
|
||||
$foo->bar = $bar;
|
||||
var_dump($foo->bar?->baz);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
||||
string(3) "baz"
|
28
Zend/tests/nullsafe_operator/036.phpt
Normal file
28
Zend/tests/nullsafe_operator/036.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Test nullsafe method call on delayed var
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Foo {
|
||||
public ?Bar $bar;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
public function baz() {
|
||||
return 'baz';
|
||||
}
|
||||
}
|
||||
|
||||
$foo = new Foo();
|
||||
|
||||
$foo->bar = null;
|
||||
var_dump($foo->bar?->baz());
|
||||
|
||||
$bar = new Bar();
|
||||
$foo->bar = $bar;
|
||||
var_dump($foo->bar?->baz());
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
||||
string(3) "baz"
|
15
Zend/tests/nullsafe_operator/037.phpt
Normal file
15
Zend/tests/nullsafe_operator/037.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Test nullsafe operator in nested delayed dims
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$foo = new stdClass();
|
||||
$foo->bar = 'bar';
|
||||
|
||||
$array = ['foo' => ['bar' => 'baz']];
|
||||
|
||||
var_dump($array['foo'][$foo?->bar]);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(3) "baz"
|
12
Zend/tests/nullsafe_operator/038.phpt
Normal file
12
Zend/tests/nullsafe_operator/038.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
Test nullsafe operator in nested delayed dims 2
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$foo = (object) ['bar' => 0];
|
||||
$array = [[null]];
|
||||
var_dump($array[0][$foo->bar]?->baz);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
Loading…
Reference in New Issue
Block a user