Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (31 sloc) 1.09 KB
// variations.php
function returnsFalse() {
return false;
function returnsNull($message='') {
if (strlen($message)) echo $message;
return null;
function defaulter(){
return 'default';
echo('<h4>defaulting null</h4>');
$result = null ?? defaulter('null');
echo "Result: [$result]<hr>";;
echo('<h4>defaulting false</h4>');
$result = false ?? defaulter('false');
echo "Result: [$result]<hr>";
echo('<h4>defaulting empty string</h4>');
$result = '' ?? defaulter('');
echo "Result: [$result]<hr>";
echo '<h4>defaulting returnsFalse()</h4>';
$result = returnsFalse() ?? defaulter('returnsFalse()');
echo "Result: [$result]<hr>";
echo('<h4>defaulting returnsNull()</h4>');
$result = returnsNull() ?? defaulter('returnsNull()');
echo "Result: [$result]<hr>";
echo('<h4>example of chaining</h4>');
$result = returnsNull('first call to returnsNull()<br>') ?? returnsNull('second call to returnsNull()<br>') ?? returnsNull('third call to returnsNull()<br>') ?? defaulter('chained');
echo "Result: [$result]<hr>";
You can’t perform that action at this time.