Re: [CONCEPT][DISCUSSION] Instance as boolean
| From: | Josh Bruce | Date: | Fri, 10 Jul 2020 14:21:32 +0000 |
| Subject: | Re: [CONCEPT][DISCUSSION] Instance as boolean | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110920@lists.php.net to get a copy of this message | ||
>>>
>>> Frankly this is something subject to personal opinions and will change
>>> over time according to community shifts.
>>>
>>
>> Not sure what's "subject to personal opinions" in the objective bug exposed
>> in the snippet above?
>>
>
> So there is a bug in a contrived code snippet therefore casting is a
> universal bad practice?
> It's at least a huge stretch. Some might say your bad practice was
> actually using
null ;)
Good stuff - very helpful (and I’m grateful), thank you both.
This might actually be an interesting (possibly the) use case for what we’re talking about.
Updated: https://bit.ly/php-0001 <https://bit.ly/php-0001>
Added pre-roll section on perceived roadblocks as I’m experiencing one.
Added “Usage” section.
Renamed code sample header to “Rationale"
***
I didn’t have a chance to look at the code linked before and tend to agree:
1. Avoid null (I’m a bit extreme with this one)
2. I tend to avoid casting as well and, if the first is followed, a casting problem could become
moot. PHP doesn’t like to halt - most primitives when cast to bool either effectively return the
result of an empty check or a not-zero check - an object, if instantiated, is always true. __toBool
would give us a way of saying it’s not true (it’s not empty, it's not zero, but it's
not okay for some reason - maybe we need to do some follow-on configuration method calls…just
making stuff up). :)
Cheers,
Josh