Re: [CONCEPT][DISCUSSION] Instance as boolean

From: Date: Thu, 09 Jul 2020 12:13:15 +0000
Subject: Re: [CONCEPT][DISCUSSION] Instance as boolean
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-110893@lists.php.net to get a copy of this message
> On Jul 8, 2020, at 12:54 PM, Marcio Almada <marcio.web2@gmail.com> wrote: > > Hello Josh, > >> Link to working draft: https://bit.ly/php-0001 >> <https://bit.ly/php-0001> > > From a type safety POV I'd prefer to have an interface available, the > same way we did > to the Stringable interface RFC. But I'd rather keep these engine > affecting behaviors > with the same magic method naming conventions and its __ > prefix. > > So implements Bool + function __toBool() : > bool is the only path that seems > entirely consistent with what we already have. > > The draft doesn't mention (bool) casting behavior at the time I'm > reading it, but you do > mention the possibility. It seems necessary to me. Why wouldn't > (bool) $my_bool_obj > behave differently from (string) $my_stringable_obj? > >> >> ps. If you have any feedback or information on social interactions here that might help, >> please do let me know, normally I would have watched for a while before putting my foot in - >> hopefully it doesn’t end up in my mouth. :) > > > Thanks, > Márcio Almada > Hello Marcio, Thank you for the input. Re casting - In the previous thread the following concern was presented and I don’t know enough about that area to respond effectively: "I'd endorse avoiding object-to-<scalar> casts via cast operations: they are a good source of bugs. My rationale for the discouragement of magic cast methods is explained with some code examples at https://github.com/ShittySoft/symfony-live-berlin-2018-doctrine-tutorial/pull/3#issuecomment-460441229 <https://github.com/ShittySoft/symfony-live-berlin-2018-doctrine-tutorial/pull/3#issuecomment-460441229>” I concur with the Stringable mention - thank you for that - I have updated based on this feedback: https://bit.ly/php-0001 <https://bit.ly/php-0001> I’ve also included a “questions outstanding” section as I could imagine people losing threads and wanted to give a way to “get up to speed” quickly. Given that the goal would be to have the class be used in place of a bool everywhere, I would think we would need to make it cast-able to a bool, yeah? Cheers, Josh ps. Thank you again. I feel like every bit of feedback causes a re-write and iteration on the presentation. Lol

« previous php.internals (#110893) next »