summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlija Tovilo <ilija.tovilo@me.com>2020-08-15 17:43:34 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-08-31 16:44:36 +0200
commit70300f6c9dcabb16740dafd017db4798c2a579e8 (patch)
tree5b74005335d74239f272394b3e4ffec7dac0920d
parent4163923e834552140879d97b9316e631d5951edd (diff)
downloadphp-git-70300f6c9dcabb16740dafd017db4798c2a579e8.tar.gz
Add tests for nullsafe operator on delayed oplines
-rw-r--r--Zend/tests/nullsafe_operator/034.phpt28
-rw-r--r--Zend/tests/nullsafe_operator/035.phpt27
-rw-r--r--Zend/tests/nullsafe_operator/036.phpt28
-rw-r--r--Zend/tests/nullsafe_operator/037.phpt15
-rw-r--r--Zend/tests/nullsafe_operator/038.phpt12
5 files changed, 110 insertions, 0 deletions
diff --git a/Zend/tests/nullsafe_operator/034.phpt b/Zend/tests/nullsafe_operator/034.phpt
new file mode 100644
index 0000000000..a82cec6b22
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/034.phpt
@@ -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
diff --git a/Zend/tests/nullsafe_operator/035.phpt b/Zend/tests/nullsafe_operator/035.phpt
new file mode 100644
index 0000000000..684c8c5d5f
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/035.phpt
@@ -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"
diff --git a/Zend/tests/nullsafe_operator/036.phpt b/Zend/tests/nullsafe_operator/036.phpt
new file mode 100644
index 0000000000..1874f733aa
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/036.phpt
@@ -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"
diff --git a/Zend/tests/nullsafe_operator/037.phpt b/Zend/tests/nullsafe_operator/037.phpt
new file mode 100644
index 0000000000..5ce49ae029
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/037.phpt
@@ -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"
diff --git a/Zend/tests/nullsafe_operator/038.phpt b/Zend/tests/nullsafe_operator/038.phpt
new file mode 100644
index 0000000000..422de0b891
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/038.phpt
@@ -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