3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // https://bugs.php.net/bug.php?id=62043 $var1 = null; $var2 = null; $var3 = $var1 ?: $var2; //$var3==null $var4 = $var1 ?: 'default1'; //$var4=='default1' $var5 = $var1 ?: $var2 ?: 'default2'; //$var5=='default2' $var6 = $var2 ?: $var3 ?: $var4 ?: 'default3'; //$var6=='default1' since the first non-null value is $var4=='default1' var_dump($var1, $var2, $var3, $var4, $var5, $var6);
Output for 5.3.0 - 7.1.0
NULL NULL NULL string(8) "default1" string(8) "default2" string(8) "default1"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/NP9ZY on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/NP9ZY on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/NP9ZY on line 6
Process exited with code 255.