3v4l.org

run code in 300+ PHP versions simultaneously
<?php function maybe_change_user_language( $selected_lang, $user_lang ) { if ( $selected_lang !== $user_lang ) { $user_lang = $selected_lang; } return $user_lang; } // Tests - Scroll to the bottom for results. function test_respect_user_language_preference( $expected, $site_lang, $user_lang, $selected_lang = 'English' ) { $user_lang = maybe_change_user_language( $selected_lang, $user_lang ); echo 'Expected: ', $expected, PHP_EOL; echo 'Actual: ', $user_lang, PHP_EOL; return 'Result: ' . ( $expected === $user_lang ? 'Pass' : 'Fail' ); } $tests = array( 'defaults with nothing selected' => array( 'expected' => 'English', 'site_lang' => 'English', 'user_lang' => 'English', 'selected_lang' => 'English', ), 'no existing preference and selects Spanish' => array( 'expected' => 'Spanish', 'site_lang' => 'English', 'user_lang' => 'English', 'selected_lang' => 'Spanish', ), 'already prefers Spanish and selects Spanish' => array( 'expected' => 'Spanish', 'site_lang' => 'English', 'user_lang' => 'Spanish', 'selected_lang' => 'Spanish', ), 'already prefers Spanish and selects nothing' => array( 'expected' => 'Spanish', 'site_language' => 'English', 'user_lang' => 'Spanish', 'selected_lang' => 'English', ), ); foreach ( $tests as $test => $args ) { $sep = str_pad( '', strlen( $test ), '=' ); echo $sep, PHP_EOL, $test, PHP_EOL, $sep, PHP_EOL; echo test_respect_user_language_preference( ...array_values( $args ) ), PHP_EOL, PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
============================== defaults with nothing selected ============================== Expected: English Actual: English Result: Pass ========================================== no existing preference and selects Spanish ========================================== Expected: Spanish Actual: Spanish Result: Pass =========================================== already prefers Spanish and selects Spanish =========================================== Expected: Spanish Actual: Spanish Result: Pass =========================================== already prefers Spanish and selects nothing =========================================== Expected: Spanish Actual: English Result: Fail

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:
64.32 ms | 407 KiB | 5 Q