Re: [RFC] [DISCUSSION] Scalar Pseudo-type

From: Date: Sun, 24 Dec 2017 16:42:35 +0000
Subject: Re: [RFC] [DISCUSSION] Scalar Pseudo-type
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-101413@lists.php.net to get a copy of this message
On 12/24/2017 5:30 PM, Nikita Popov wrote: > I think this RFC could benefit from displaying some use-cases for this type > annotation. I can't recall any recent instance where I would have found > this specific type combination useful, though I'm sure there are good > examples. > > I also wonder whether in weak typing mode, scalar should also accept > __toString objects (and cast them to string), similarly to how a > bool|int|float|string union would behave. > > Nikita > I will extend it with some examples. I guess that that would be useful in weak mode. Will try to hack it in. I am currently also working on another RFC that adds a Convertible interface with a single into method that has its return type set to scalar where objects can opt-in to become scalar compatible. Even in strict mode. The idea is that the object's into method is automatically called by the engine and the receiver gets the canonical scalar value that represents the object. This is specifically useful for value objects that often represent single scalar values in a type safe manner. -- Richard "Fleshgrinder" Fussenegger

« previous php.internals (#101413) next »