Hi Enno, czw., 16 kwi 2020 o 12:20 Enno Woortmann <enno.woortm...@web.de> napisał(a):
> Hi together, > > as the voting for the "Type casting in array destructuring expressions" > shows a clear direction to be declined (sad faces on my side, I really > would've liked it as a feature completion of the casting feature set > without the need for a really new syntax, as the parser also already > coverred it, but ok, time to continue :D ), combined with a strong > interest for the topic "type checks in array destructuring expressions" > (as well in the discussion as in the vote) I've set up a first draft of > an RFC covering this topic: > > https://wiki.php.net/rfc/typehint_array_desctructuring > > The discussion around the casting in array destructuring brought up the > idea to perform regular type checks in array destructuring expressions. > This RFC proposes a new syntax to type hint a variable inside an array > destructuring expression: > > $data = [42, 'Example', 2002]; > [int $id, string $data, int $year] = $data; > > 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); And then expect the $id to behave more like typed property with type guard. At least this is me what would expect from putting a type in from of variable name like in array destructuring example. Why? Cause it has a type constraint in from of variable name just like typed properties have. Cheers, Michał Brzuchalski