On Wed, Nov 2, 2022 at 1:12 AM Michał Marcin Brzuchalski < michal.brzuchal...@gmail.com> wrote:
> Hi Josh, > > Have you tried not initializing invalid objects? This could help you. > Also that sounds more logical to me as I don't see any reasons to > initialize invalid objects if it's a matter of simple validation instead. > > P.S. I don't see it feasible to have objects that evaluate false in > logical expressions. > > Cheers, > Michał Marcin Brzuchalski > The one situation in which I can think of where an object might legitimately have a falsey bool casting is if it represents a single value (that may have multiple properties associated with it, like units of measurement), and `if ($obj)` is really asking something like `if ($obj->castSingleValuePropertyToBool())`. For most of *these* situations, either `if ($obj->isEqual(0))` is equivalent, or `if ($obj == 0)` is equivalent if operator overloading was accepted. Jordan