Re: [RFC][Discussion] Objects can be declared falsifiable

From: Date: Wed, 15 Jul 2020 21:42:51 +0000
Subject: Re: [RFC][Discussion] Objects can be declared falsifiable
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-111032@lists.php.net to get a copy of this message
Hi, Implement an interface and magic method to allow objects to represent false > (or empty) while still be valid instances of the custom object (type). > > https://wiki.php.net/rfc/objects-can-be-falsifiable < > https://wiki.php.net/rfc/objects-can-be-falsifiable> > > If you saw the latest from this morning, not much has changed except > hopefully improved formatting and now being the official mix of things. > > If this is your first time, the cues are taken from: > > - __toString() > - Stringable > - and __toArray() (not accepted or approved yet) > > Thank you for all the feedback and patience so far, appreciate it! > > If I'm not mistaken, other languages use different methods to express emptiness and falsyness and sometimes these methods have the same implementation sometimes not. So I think it's good that the RFC scope retracted a bit. For instance, in Pyhton it's common to see code like: class test: def __bool__(self): return False __nonzero__=__bool__ BTW, I'm not saying you should pursue both RFCs or anything, that's just a reference in case you are looking around how others did it. Ty, Márcio

« previous php.internals (#111032) next »