From: Operating system: Any PHP version: 5.3.3 Package: *General Issues Bug Type: Feature/Change Request Bug description:Enhancement / change to array_flip() with boolean values
Description: ------------ This is not a bug, but I propose a change to how array_flip operates with boolean values, in order to improve common use cases, because: 1) The current behavior (warning and completely empty array) renders arrays with one or more boolean values invalid for flipping so they have to be manually filtered in advance. 2) When true/false are cast to 1/0, all loose type checks against the keys will match (i.e. true == 1, false == 0) which makes the cast also a practical one for real utility. 3) The change will make the casting behavior of array_flip consistent with the *already* existing behavior in the following example: // casts booleans to int, and produces: array(1 => 123, 0 => 321); $a = array(); $a[true] = 123; $a[false] = 321; Test script: --------------- var_dump( array_flip( array('foo' => true, 'bar' => false) ) ); Expected result: ---------------- array(2) { [1]=> string(3) "foo" [0]=> string(3) "bar" } Actual result: -------------- Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in ... on line 2 array(0) { } -- Edit bug report at http://bugs.php.net/bug.php?id=53038&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53038&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53038&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53038&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53038&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53038&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53038&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53038&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53038&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53038&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53038&r=support Expected behavior: http://bugs.php.net/fix.php?id=53038&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53038&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53038&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53038&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53038&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53038&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53038&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53038&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53038&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53038&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53038&r=mysqlcfg