3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getusername($user) { return 'genericUser'; } function test ($user) { { // original question $usernameA = $user ?: getusername($user); echo '$usernameA = ', var_export($usernameA, true), PHP_EOL; } { // equivalent if( $user ) { $usernameB = $user; } else { $usernameB = getusername($user); } echo '$usernameB = ', var_export($usernameB, true), PHP_EOL; } } $testCases = array('someUser', true, '', null, false, 0, @$undefined); foreach ( $testCases as $testCase ) { echo 'test with ', var_export($testCase , true) ,' ...', PHP_EOL; test($testCase); echo 'test with ', var_export($testCase , true) ,' DONE.', PHP_EOL; echo PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
test with 'someUser' ... $usernameA = 'someUser' $usernameB = 'someUser' test with 'someUser' DONE. test with true ... $usernameA = true $usernameB = true test with true DONE. test with '' ... $usernameA = 'genericUser' $usernameB = 'genericUser' test with '' DONE. test with NULL ... $usernameA = 'genericUser' $usernameB = 'genericUser' test with NULL DONE. test with false ... $usernameA = 'genericUser' $usernameB = 'genericUser' test with false DONE. test with 0 ... $usernameA = 'genericUser' $usernameB = 'genericUser' test with 0 DONE. test with NULL ... $usernameA = 'genericUser' $usernameB = 'genericUser' test with NULL DONE.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
31.76 ms | 407 KiB | 5 Q