Re: Type hints in array destructuring expressions
| From: | Nicolas Grekas | Date: | Thu, 16 Apr 2020 10:48:34 +0000 |
| Subject: | Re: Type hints in array destructuring expressions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109679@lists.php.net to get a copy of this message | ||
> > https://wiki.php.net/rfc/typehint_array_desctructuring
>
Thanks, Enno, I like it a lot!
I hope the implementation won't find any blocker.
> I fear that if you go that path people would automatically expect it to be
> possible to write:
>
> int $id = $data['id'];
> int $id = getIdFromData($data);
>
That would be a nice addition I guess - maybe for a separate RFC to keep
the focus clear on this one.
> And then expect the $id to behave more like typed property with type guard.
>
I would not expect the type guard on my side, like function arguments don't
provide type guards and also because this is PHP: runtime checks slow down
the engine. Thus I would expect this to be guarded by static type analyzers
for ppl who care (I'm not sure it matters personally, see SSA
transformations), and on assignation otherwise to balance perf vs runtime
overhead. (Note that the expectation you describe is a valid one, I'm just
explaining that a different expectation exists, and why)
Nicolas