Re: [RFC] Mixed type

From: Date: Mon, 20 Apr 2020 17:01:37 +0000
Subject: Re: [RFC] Mixed type
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-109727@lists.php.net to get a copy of this message
As Larry was asking for an example. The ParameterBag::get() function from Symfony (and others) that allows you to fetch request params, for example. That's a mixed type that could return different values, depending on your request body. Yes, I can type for all possible scalar values + null + array, but that's a bit of a PITA and phpstan would complain nonetheless, as the return type of theParameterBag ::get() function is "mixed" and we can't change that. Right now we're annotating "mixed" with a docblock. So yes, a "mixed" type is greatly appreciated when dealing with user input. Thanks! On Mon, Apr 20, 2020 at 6:41 PM Guilliam Xavier <guilliam.xavier@gmail.com> wrote: > On Mon, Apr 20, 2020 at 5:17 PM Larry Garfield <larry@garfieldtech.com> > wrote: > > > > With union types and stringable already on the way, I'm not sure what > other non-hypothetical use cases would still be that fugly that you'd now > need to fall back to mixed. > > For instance: > - the parameter of [a wrapper around] gettype() or an is_* function > - the return of [a generic implementation of] > ArrayAccess::offsetGet() or Iterator::current(), or of a userland > array_value_first() or array_value_last() function > > To me, especially the return type declaration can be useful to ensure > that [every code path of] the implementation returns a value. > > -- > Guilliam Xavier > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#109727) next »