One of the things that you’ll quickly learn if you use PHP for anything substantial is that its dynamic (free and easy) type casting and general attitude towards variables often means you have to write more code to check things are as you expect they should be to actually make your code stable.
A case in point, when you want to test for equality you usually use double equals signs (==) but php also reports the int 0 as false if you test for it, an empty array as false, empty string. This might be the behaviour you want. But if you want to test for a zero test for it don’t rely on type casting for it. My recommendation is to try and use equality testing with type matching too. This can be achieved with a triple equals sign (===) or for a negative test !== .