A few days ago, zero asked if there was a way to convert data from WCS to War3Source. “Of course,” I replied. This morning I made a simple PHP script which simply iterated through the existing entries a few times to convert this data. I wanted to ignore bot data, since if I was to ever actually add bot data it wouldn’t be saved, but rather randomized depending on current server conditions. Anyway, to achieve this I found the PHP function strpos() which simply finds a substring inside a string and returns the position, if none is found FALSE is returned. However, since FALSE evaluates to 0, if the string was found at position 0 then my if-statement was going to fail. Turns out, from the PHP documentation:
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
I find this kind of odd. Why not just return -1 for not found? Who knows, but according to KnyghtMare of the #php channel: “[I]t seems the functions in the php core are meant to show off the [PHP] type juggling.”
I agree, this seems quite odd to me though, I still believe that an integer comparison to -1 is quicker than checking type and value, but I suppose it doesn’t matter much.