summaryrefslogtreecommitdiff
path: root/Zend/tests/021.phpt
diff options
context:
space:
mode:
authorJohannes Schlüter <johannes@php.net>2007-11-21 00:03:16 +0000
committerJohannes Schlüter <johannes@php.net>2007-11-21 00:03:16 +0000
commit4a8ed7ab68a398d8eb79ab4d82c5e30e3f496fae (patch)
treeac487aae75fe3359ea052370e450bcf574bab586 /Zend/tests/021.phpt
parent204f9e1a7429526b5ed8ff3f4cd65df0146a5da7 (diff)
downloadphp-git-4a8ed7ab68a398d8eb79ab4d82c5e30e3f496fae.tar.gz
- MFH ?: operator (Marcus)
[DOC] "expr1 ?: expr1" is a shortcut for: "expr1 ? expr1 : expr2" as exists in gcc and discussed some time back. Note that this is not an implementation ifsetor($var, default). While ifsetor would not generate any message for non existing variables or array indices the ternary shortcut does. Also the ternary shortcut does a boolean evaluation rather then checking for isset(). That way ther ternary shortcut can work on any expression while ifsetor can only work on variables. Also to be silent one has do do: "@$expr1 ?: $expr2".
Diffstat (limited to 'Zend/tests/021.phpt')
-rw-r--r--Zend/tests/021.phpt27
1 files changed, 27 insertions, 0 deletions
diff --git a/Zend/tests/021.phpt b/Zend/tests/021.phpt
new file mode 100644
index 0000000000..99fdb50258
--- /dev/null
+++ b/Zend/tests/021.phpt
@@ -0,0 +1,27 @@
+--TEST--
+?: operator
+--FILE--
+<?php
+var_dump(true ?: false);
+var_dump(false ?: true);
+var_dump(23 ?: 42);
+var_dump(0 ?: "bar");
+
+$a = 23;
+$b = 0;
+$c = "";
+$d = 23.5;
+
+var_dump($a ?: $b);
+var_dump($c ?: $d);
+
+var_dump(1 ?: print(2));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+int(23)
+string(3) "bar"
+int(23)
+float(23.5)
+int(1)