summaryrefslogtreecommitdiff
path: root/tests/lang/operators
diff options
context:
space:
mode:
authorAndrea Faulds <ajf@ajf.me>2014-09-28 00:07:04 +0100
committerAndrea Faulds <ajf@ajf.me>2014-09-28 00:07:04 +0100
commit2d069f640e6cccfa3ba8b1e4f375ade20fb33f64 (patch)
treee6edf9822fe559eae0506c75c83286d404c822be /tests/lang/operators
parentf13da5b0d72dc8dfcc5e7d4ae11556a92c36ce53 (diff)
parentec39802e4e7dac14b629f41017d04573a6a5fdc4 (diff)
downloadphp-git-2d069f640e6cccfa3ba8b1e4f375ade20fb33f64.tar.gz
Merge branch 'coalesce_operator'
* coalesce_operator: Extended coalesce operator test case for ordering/short-circuiting Ensure not evaluated twice Added test Initial coalesce operator implementation
Diffstat (limited to 'tests/lang/operators')
-rw-r--r--tests/lang/operators/coalesce.phpt79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/lang/operators/coalesce.phpt b/tests/lang/operators/coalesce.phpt
new file mode 100644
index 0000000000..2ee54c5276
--- /dev/null
+++ b/tests/lang/operators/coalesce.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Test ?? operator
+--FILE--
+<?php
+
+$var = 7;
+$var2 = NULL;
+
+$obj = new StdClass;
+$obj->boo = 7;
+
+$arr = [
+ 2 => 7,
+ "foo" => "bar",
+ "foobar" => NULL,
+ "qux" => $obj,
+ "bing" => [
+ "bang"
+ ]
+];
+
+function foobar() {
+ echo "called\n";
+ return ['a'];
+}
+
+var_dump($nonexistant_variable ?? 3);
+echo PHP_EOL;
+var_dump($var ?? 3);
+var_dump($var2 ?? 3);
+echo PHP_EOL;
+var_dump($obj->boo ?? 3);
+var_dump($obj->bing ?? 3);
+var_dump($arr["qux"]->boo ?? 3);
+var_dump($arr["qux"]->bing ?? 3);
+echo PHP_EOL;
+var_dump($arr[2] ?? 3);
+var_dump($arr["foo"] ?? 3);
+var_dump($arr["foobar"] ?? 3);
+var_dump($arr["qux"] ?? 3);
+var_dump($arr["bing"][0] ?? 3);
+var_dump($arr["bing"][1] ?? 3);
+echo PHP_EOL;
+var_dump(foobar()[0] ?? false);
+echo PHP_EOL;
+function f($x)
+{
+ printf("%s(%d)\n", __FUNCTION__, $x);
+ return $x;
+}
+
+$a = f(null) ?? f(1) ?? f(2);
+?>
+--EXPECTF--
+int(3)
+
+int(7)
+int(3)
+
+int(7)
+int(3)
+int(7)
+int(3)
+
+int(7)
+string(3) "bar"
+int(3)
+object(stdClass)#%d (%d) {
+ ["boo"]=>
+ int(7)
+}
+string(4) "bang"
+int(3)
+
+called
+string(1) "a"
+
+f(0)
+f(1) \ No newline at end of file