array_flip() null & boolean

From: Date: Wed, 24 Feb 2021 01:03:12 +0000
Subject: array_flip() null & boolean
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232368@lists.php.net to get a copy of this message
ref.: https://bugs.php.net/bug.php?id=53038 I'm not the author of this bug report, but I encounter a similar problem with the NULL key that is rejected, even if a NULL key is equivalent to an empty string key. In my case, I had an array with a series of string value and one NULL value meant to work with a database output (returning a string type or NULL). Now, I have to set the value to an empty string, and when entering a NULL value from the database into the (flipped) array key, PHP converts it to the empty string key automatically. If I had two NULL values, one would overwrite the other, I understand. But if I had two empty strings, the same reasoning would apply. It's up to the programmer to take care of this limitation. I don't see the harm in accepting NULL & boolean values in array_flip(), when PHP considers them valid keys in arrays, even if they are actually converted to "", 0 or 1.

« previous php.bugs (#232368) next »