On Wed, 29 Dec 2021, 15:42 Vincent Langlet, <misterdevil...@gmail.com> wrote:
> > I recently discovered that an array was automatically casting > numeric-string keys to int if it was possible. > Having had to track down bugs numerous times over the years, I completely agree this is unexpected behaviour, and would be in favour of it being amended. It is quite a BC break indeed, and both Orklah (Psalm) and Ondrej Mirtes (PHP Stan) agree that the issue is that it's a difficult issue to identify with static analysis (see https://twitter.com/OndrejMirtes/status/1478971968636567552 for some thoughts). As always with type juggling related discussions in PHP, I expect any RFC to be contentious and heavily discussed ;) I expect the main detractors would be the BC breaks, and people might not think the BC break is worth the pain. 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. That said, I know there has been contentious discussion on this and the related topic of generics multiple times, so don't really want to stir up a hornet's nest there. Great idea, and I'd love to see this fixed, given the countless hours I've wasted trying to track down bugs that are a result of this. But I fear that this would be a difficult one to push through the RFC process, sadly. I hope I'm proven wrong though! Thanks James >