mirror of
https://github.com/php/php-src.git
synced 2024-09-25 03:47:26 +00:00
4a8ed7ab68
[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".
28 lines
320 B
PHP
28 lines
320 B
PHP
--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)
|