3v4l.org

run code in 200+ PHP versions simultaneously
<?php $results = []; foreach ([ '', 'a', ] as $str) { $strx = var_export($str, true); foreach ([ 0, 5, ] as $num) { $results["$strx ?: $num"] = $str ?: $num; $results["$strx ?: $num ?: false"] = $str ?: $num; $results["($strx ?: $num) ?: false"] = $str ?: $num; $results["$strx ?: ($num ?: false)"] = $str ?: $num; $results["$strx ? ($num ?: false) : false"] = $str ? ($num ?: false) : false; $results["$strx ? $num ?: false : false"] = $str ? $num ?: false : false; } } foreach ($results as $formula => $result) { print var_export($result, true) . ' === ' . $formula . "\n"; }
based on nZFZC
Output for 7.1.25 - 7.4.0
0 === '' ?: 0 0 === '' ?: 0 ?: false 0 === ('' ?: 0) ?: false 0 === '' ?: (0 ?: false) false === '' ? (0 ?: false) : false false === '' ? 0 ?: false : false 5 === '' ?: 5 5 === '' ?: 5 ?: false 5 === ('' ?: 5) ?: false 5 === '' ?: (5 ?: false) false === '' ? (5 ?: false) : false false === '' ? 5 ?: false : false 'a' === 'a' ?: 0 'a' === 'a' ?: 0 ?: false 'a' === ('a' ?: 0) ?: false 'a' === 'a' ?: (0 ?: false) false === 'a' ? (0 ?: false) : false false === 'a' ? 0 ?: false : false 'a' === 'a' ?: 5 'a' === 'a' ?: 5 ?: false 'a' === ('a' ?: 5) ?: false 'a' === 'a' ?: (5 ?: false) 5 === 'a' ? (5 ?: false) : false 5 === 'a' ? 5 ?: false : false