3

my friend and me found this while debugging an application

<?php

echo "check: " . ('x' == 0);

?>

This code prints 1 (so, it is true, x equals to 0). Can somebody explain why it is? I think may be I dont understand something in php rules... or may be it is a bug?

Thank you.

Andrey
  • 712
  • 6
  • 16

1 Answers1

4

The string is converted to a number using "type juggling". This is shown in the documentation, too.

For this particular case, the string doesn't start with a number, so it becomes equal to 0 when cast.