Edit report at http://bugs.php.net/bug.php?id=51384&edit=1
ID: 51384 Updated by: fel...@php.net Reported by: info at fedushin dot ru Summary: Allow array keys "0", "1", etc. -Status: Open +Status: Bogus Type: Bug Package: Arrays related PHP Version: 5.3.2 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php See bug #45959 Previous Comments: ------------------------------------------------------------------------ [2010-03-24 23:34:35] info at fedushin dot ru Description: ------------ PHP Manual says about arrays: "A key may be either an integer or a string .". But which strings can be used as key? Even rather experienced programmer will answer: any, and will be wrong. In fact, there's no way to use string keys "0", "1", etc. because they are implicitly converted into integer keys. So, PHP engine's behaviour in this case should be considered as unpredictable. This problem is rejected in Bug #9307, sorry for repetition. Then, let's ask our experienced programmer what output will be generated by the following script: <?php // Assume we have already made successful mysql_connect(). $res = mysql_query('SELECT 1, "aaa";'); $row = mysql_fetch_array($res); echo $row[0] . '<br>'; echo $row[1] . '<br>'; ?> I think very few people will give correct answer: 1 1 So again we have unpredictable behaviour. Suggestion is to improve this situation: 1. Allow storing values in PHP arrays under string keys .., "-1", "0", "1", ... 2. Always use strings & never use integers as associative indices in arrays returned by mysql_fetch_array(). Test script: --------------- $a = array(); $a[1] = 'aaa'; $a['1'] = 'bbb'; var_dump($a); $res = mysql_query('SELECT 1, "aaa";'); $row = mysql_fetch_array($res); var_dump($row); Expected result: ---------------- array 1 => string 'bbb' (length=3) '1' => string 'bbb' (length=3) array 0 => string '1' (length=1) '1' => string '1' (length=1) 1 => string 'aaa' (length=3) 'aaa' => string 'aaa' (length=3) Actual result: -------------- array 1 => string 'bbb' (length=3) array 0 => string '1' (length=1) 1 => string '1' (length=1) 2 => string 'aaa' (length=3) 'aaa' => string 'aaa' (length=3) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51384&edit=1