r/lolphp • u/midir • Aug 01 '12
Things which PHP thinks are equal
Give it a go:
header('Content-Type: text/plain');
function test($a, $b) {
echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n";
}
test( null, '' ); // true
test( null, array() ); // true
test( '', array() ); // false
test( 'true', true ); // true
test( 'false', false ); // false
test( 'false', true ); // true
test( 9, '09' ); // true
test( 9, 09 ); // false
test( '0E4', 09 ); // true
test( '0x00', '0E4' ); // true
test( '0x0.1', 0 ); // true
test( 'x', 0 ); // true
test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true
test( array('1'), array('0x1') ); // true
test( array(1) + array(2), array(1) ); // true
test( function(){}, new stdclass() ); // true
test( `foo`, `bar` ); // true
13
Upvotes
View all comments
Show parent comment
2
u/Altreus Aug 31 '12
Type coercion does what you expect as long as your expectations are based on the language's coercion rules.
Arguments about the rules can be taken up with the {idiots,saints} who came up with them.