Re: RFC: Stop to automatically cast numeric-string to int when using them as array-key

From: Date: Fri, 07 Jan 2022 10:35:18 +0000
Subject: Re: RFC: Stop to automatically cast numeric-string to int when using them as array-key
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-116845@lists.php.net to get a copy of this message
> On 6 January 2022 07:29:58 GMT, James Titcumb <james@asgrim.com> wrote: > >Just thinking out loud, being able to identify an array type might be a > way > >forward here (using "syntax" already in use by static analysis tools in > >docblocks, for familiarity), e.g. > > > >private array<string, mixed> $property; > > > >This might "turn off" the automatic type juggling behaviour, for example. > >If the existing strict_types=1 mode is on, this might fail: > > > >$this->property[3] = "hi"; > > > >If strict_types=0 or not declared, the key would be cast to a string. > > > Yes, something similar occurred to me earlier, and I honestly think that > some new types like this are the only way this can practically be solved. > > So a solution, which doesn't require generics, would be to introduce something new like a dict as a way to create an array<string, mixed>. {} could be used instead of []. $dict = {'1' => '1', 'key' => 'value'}; \is_array($dict); // true

« previous php.internals (#116845) next »