9

Hey everyone!
Today I learned that true is not boolean and my functions typed for bool can actually return bool OR true!

Comments
  • 1
    I saw this thing in Typescript, but not actually bool|true, but it does that if bool is null then default is true. But is bool nullable by default in php? I know that default value is false ...
  • 2
    @gitpush

    No. And yes. My PHP code is very strict with this stuff. You can hardtype in PHP pretty much anything, and boolean will not allow anything but true|false. If you flip switch in php config, providing (int) 0 will cause crush. That's env I code in. I love type safety/enforcing.

    But you can flip switch off in PHP ini file so it will change for example (int) 0 into false. But i'm not sure if it will do null into false. If I will get null, I will know about it and do it very explicitly.

    Nontheless, it's funny how PHPstorm told me that it's boolean OR true. Laughed a bit.
  • 1
    @DubbaThony yup one funny bug lol, its like: it might be a boolean but also a 'true' which is totally a valid boolean value. I don't know, just take it or leave it! lol
Add Comment