3v4l.org

run code in 300+ PHP versions simultaneously
<?php function force_ssl_admin( $force = null ) { static $forced = false; if ( ! is_null( $force ) ) { $old_forced = $forced; $forced = $force; return $old_forced; } return $forced; } function new_force_ssl_admin( $force = null ) { static $forced = false; if ( ! is_null( $force ) ) { $old_forced = $forced; $forced = (bool) $force; return $old_forced; } return $forced; } $datasets = array( 'null' => array( 'force' => null, 'expected' => false, ), '(bool) true' => array( 'force' => true, 'expected' => true, ), '(bool) false' => array( 'force' => false, 'expected' => false, ), '(int) 1' => array( 'force' => 1, 'expected' => true, ), '(int) 0' => array( 'force' => 0, 'expected' => false, ), '(string) "1"' => array( 'force' => '1', 'expected' => true, ), '(string) "0"' => array( 'force' => '0', 'expected' => false, ), '(float) 1.0' => array( 'force' => 1.0, 'expected' => true, ), '(float) 0.0' => array( 'force' => 0.0, 'expected' => false, ), '(string) "true"' => array( 'force' => 'true', 'expected' => true, ), '(string) "false"' => array( 'force' => 'false', 'expected' => true, // (bool) "false" === true ), 'empty string' => array( 'force' => '', 'expected' => false, ), 'string with only spaces' => array( 'force' => ' ', 'expected' => true, ), 'non-empty array' => array( 'force' => array( 'item' ), 'expected' => true, ), 'empty array' => array( 'force' => array(), 'expected' => false, ), 'non-empty object' => array( 'force' => (object) array( 'item' ), 'expected' => true, ), 'empty object' => array( 'force' => (object) array(), 'expected' => true, ), ); foreach( $datasets as $test => $data ) { list( $force, $expected ) = array_values( $data ); force_ssl_admin( $force ); new_force_ssl_admin( $force ); $old = (bool) force_ssl_admin(); $new = new_force_ssl_admin(); echo str_pad( $test . ': ', max( array_map( 'strlen', array_keys( $datasets ) ) ) + 2 ); $bc = $new === $old; $assert = $new === $expected; if ( $bc && $assert ) { echo 'Matches expected value and old value casted to bool.'; } if ( ! $bc ) { echo 'BC break. '; } if ( ! $assert ) { echo "Incorrect value. \n"; echo '-', var_export( $expected, true ), "\n"; echo '+', var_export( $new, true ), "\n"; } echo "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
null: Matches expected value and old value casted to bool. (bool) true: Matches expected value and old value casted to bool. (bool) false: Matches expected value and old value casted to bool. (int) 1: Matches expected value and old value casted to bool. (int) 0: Matches expected value and old value casted to bool. (string) "1": Matches expected value and old value casted to bool. (string) "0": Matches expected value and old value casted to bool. (float) 1.0: Matches expected value and old value casted to bool. (float) 0.0: Matches expected value and old value casted to bool. (string) "true": Matches expected value and old value casted to bool. (string) "false": Matches expected value and old value casted to bool. empty string: Matches expected value and old value casted to bool. string with only spaces: Matches expected value and old value casted to bool. non-empty array: Matches expected value and old value casted to bool. empty array: Matches expected value and old value casted to bool. non-empty object: Matches expected value and old value casted to bool. empty object: Matches expected value and old value casted to bool.

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:
29.26 ms | 409 KiB | 5 Q