Re:Modern PHP features explained – PHP 8.0 and 8.1
by tyingq on Thursday October 27, 2022 @11:16AM
(#33358823)
Lots of answers on using the type support that is there, but some use of forced casting is also common, as is using === when appropriate, avoiding "if ($bool)" in favor of "if ($bool === true)" for boolean comparisons, using linters, static analyzers, and so on.
[ Parent
| on HN ]
Re:Modern PHP features explained – PHP 8.0 and 8.1
by jw1224 on Thursday October 27, 2022 @02:16PM
(#33361671)
> using === when appropriate
It’s always appropriate. A good IDE should highlight == as a warning.
My code quality and programming abilities got significantly better since forcing strict types and comparisons on myself. I can’t imagine writing PHP any other way now.
Re:Modern PHP features explained – PHP 8.0 and 8.1
by rossriley on Thursday October 27, 2022 @10:28PM
(#33366843)
There are a few instances where using == is desirable, for instance it allows you to compare two instances of an object and returns true if the properties are the same.
In this case === will always return false since it checks if the two instances are the same object.