Re: [RFC][Discussion] Objects can be declared falsifiable
| From: | Jordan LeDoux | Date: | Wed, 02 Nov 2022 21:08:50 +0000 |
| Subject: | Re: [RFC][Discussion] Objects can be declared falsifiable | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118944@lists.php.net to get a copy of this message | ||
On Wed, Nov 2, 2022 at 1:12 AM Michał Marcin Brzuchalski <
michal.brzuchalski@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