Esquire Theme by Matthew Buchanan
Social icons by Tim van Damme

03

Jun

‘string’ == true, 0 == false, ‘string’ == 0

What happens in the follow piece of code?

$a = ‘string’;

$b = 0;

if($a == true && $b == false && $a == $b) {

echo ‘hum rum’;

}

  • In ‘string’ == true, any non-null string evaluates to true when compared with a Boolean.
  • In 0 == false, the integer 0 undergoes implicit conversation to Boolean and evaluates to false. 
  • In ‘string’ == 0, a string is silently promoted to integer when compared to an integer.