[Concept] Don't cast keys in array to int

From: Date: Mon, 17 Aug 2020 00:56:35 +0000
Subject: [Concept] Don't cast keys in array to int
Groups: php.internals 
Request: Send a blank email to internals+get-111566@lists.php.net to get a copy of this message
I’m sure this conversation has happened before. But it’s on my mind as I work on some things on wanted to ask internals real quick before getting back to it. [“2” => “hello”, “4” => “internals”] -> [2 => “hello”, 4 => “internals”] Meanwhile: [“hello”, “internals”] -> cast to object -> (“0” => “hello”, “2” => “internals”) Curious why this it’s the case that specifically requesting a string be a key that happens to be an integer, becomes an int type. I kind of understand why in the case of object the implicit (PHP-established) integers become strings. And, of course, casting back puts us back to an indexed array. I’ve picked up that type juggling might be a touchy point - but the focus is on why the key gets cast at all when it’s an array type. Is it to facilitate the type juggle from an object to an array?? Cheers, Josh

« previous php.internals (#111566) next »