| ▲ | tredre3 21 hours ago | |
Internally PHP has three distinct array types (the distinction is mainly for optimization purposes, it doesn't enforce anything): Regular arrays (continuous numeric keys), sparse arrays (all keys are integers but there can be holes) and hashmaps (anything goes). I wish that the implicit casting you describe only happened in the two first case. In your example PHP already knows that $foo is a hashmap, so I'd want it to keep '1' as is! Unfortunately for all of us, for every person surprised by this behavior, there's someone who relies on it. So it'll never change. Best we can hope is to have better array types eventually (no, the SPL isn't it). | ||