From: dharma dot yp at in dot ibm dot com Operating system: Windows, Linux PHP version: 5.2CVS-2007-10-18 (snap) PHP Bug Type: Arrays related Bug description: array_fill() function's inconsistent behavior in PHP5 and PHP6
Description: ------------ 1) In php 5 when following values are given as value for $start_key, the values are not automatically converted and used,A warning message is displayed. However automatic conversion of these values happen in php6 and the converted values are used, hence no warning messages generated. The $start_key values are : null, NULL, true, false, TRUE, FALSE. The warning message generated in php5 is : Warning: array_fill(): Wrong data type for start key in %s on line %d bool(false) 2) In php6 when empty string("" & '') is given as $start_key the array_fill() function generates an warning however in php5 it doesn't. conversion happens and the value is used. The warning message generated in php6 is : Warning: array_fill() expects parameter 1 to be long, string given in %s on line 3 NULL Please note that documentation doesn't say any thing in specific for these but looking at array type documentation( http://in.php.net/manual/en/language.types.array.php ), an array could have any of these as key. Since this function is doing the creation of an array with specified values, it should create array in all possible ways, that can be created in general using array(). If not, then one would have to write an work-around code when these value are to be passed to array_fill(). Reproduce code: --------------- 1) null and boolean values as $start_key <?php var_dump( array_fill(TRUE, 2, 100) ); var_dump( array_fill(NULL, 2, 100) ); ?> 2) empty string value as $start_key <?php var_dump( array_fill("", 2, 100) ); ?> Expected result: ---------------- 1) null and boolean values as $start_key array(2) { [1]=> int(100) [2]=> int(100) } array(2) { [0]=> int(100) [1]=> int(100) } 2) empty string value as $start_key array(2) { [0]=> int(100) [1]=> int(100) } Actual result: -------------- 1) null and boolean values as $start_key on php5: Warning: array_fill(): Wrong data type for start key in %s on line %d bool(false) Warning: array_fill(): Wrong data type for start key in %s on line %d bool(false) on php6: array(2) { [1]=> int(100) [2]=> int(100) } array(2) { [0]=> int(100) [1]=> int(100) } 2) empty string value as $start_key on php6: Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d NULL Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d NULL on php5: array(2) { [0]=> int(100) [1]=> int(100) } -- Edit bug report at http://bugs.php.net/?id=43017&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43017&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43017&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43017&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43017&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43017&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43017&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43017&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43017&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43017&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43017&r=support Expected behavior: http://bugs.php.net/fix.php?id=43017&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43017&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43017&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43017&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43017&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43017&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43017&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43017&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43017&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43017&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43017&r=mysqlcfg