Re: [RFC] Mixed type
| From: | Dan Ackroyd | Date: | Tue, 21 Apr 2020 11:29:55 +0000 |
| Subject: | Re: [RFC] Mixed type | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109749@lists.php.net to get a copy of this message | ||
On Mon, 20 Apr 2020 at 16:17, Larry Garfield <larry@garfieldtech.com> wrote:
> I... cannot actually envision what code would actually accept that mess. :-)
var_dump() would be one example. Also caches that can store any
userland value would be another reasonably common use.
The general pattern is when you're handling someone else's 'data' and
have no restrictions on what type that data should be. That's actually
the use-case that prompted me to help draft this RFC.
> now that we have Union types what places are
> there where the currently available type declarations are insufficient?
A type that explicitly allows any type is more forwards compatible
than writing out a union type.
Compare this:
var_dump( mixed $expression [, mixed $... ] ) : void
to:
var_dump( null|bool|int|float|string|array|object|resource $expression
[, null|bool|int|float|string|array|object|resource $... ] ) : void
If/when we add an 'enum' type that is not a child type of any of the
current types, the signature of that function doesn't need to change
if it uses mixed, rather than the written out union type.
Also, the 'fitting on a line' problem.
cheers
Dan
Ack