Hi Nicolas, czw., 16 kwi 2020 o 12:48 Nicolas Grekas <nicolas.grekas+...@gmail.com> napisał(a):
> > > 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) > > Agree this would slow things down but if it could be potentially type checked on the assignment with type constraint in front of the variable name I think that would be a neat feature. So to work as a function parameter but not like a typed property. Cheers, Michał Brzuchalski