From: Operating system: Fedora/Ubuntu PHP version: 5.3.8 Package: Scripting Engine problem Bug Type: Bug Bug description:is_array throws E_NOTICE on undefined array elements, isset does not.
Description: ------------ I have a sparse matrix, that needs each element to display on an html page. So when the matrix is loaded with defined values there are many undefined values, 6158 for example. This is displayed as a square matrix using an HTML table - A conflict between good PHP programming and HTML programming. The undefined elements need some html, so the 'for loops' must touch each element of the array to display the square set of values. is_array is the correct call to use. It tests array elements, and returns true or false if they are valid or not. While the is_array function returns true and false - PHP still issues the warning message. is_array is a test, not an operation on a null value, and therefore not bad programming requiring a message. http://rickfoosusa.blogspot.com/2011/09/howto-clear-php-undefined-offset.html Test script: --------------- $data_array=array(); $data_array[2][10] = "defined"; $row_count = 10; $col_count = 10; //...fill with the defined values...many values undefined. for ($r = 0; $r < $row_count; $r++) { echo "<tr>"; for ($c = 0; $c < $col_count; $c++) { if (isset($data_array[$r+1][$c+1])){ $data = $data_array[$r+1][$c+1]; } else { $data = NULL; } echo "<td>"; } } Expected result: ---------------- True or False depending if the array element is valid. Actual result: -------------- True or False depending if the array element is valid. PHP Notice: Undefined offset: 118 in /usr/share/resultsdb/www/index.php on line 465, referer: http://134.86.96.216/resultsdb/index.php? -- Edit bug report at https://bugs.php.net/bug.php?id=55772&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55772&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55772&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55772&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55772&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55772&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55772&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55772&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55772&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55772&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55772&r=support Expected behavior: https://bugs.php.net/fix.php?id=55772&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55772&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55772&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55772&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55772&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55772&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55772&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55772&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55772&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55772&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55772&r=mysqlcfg
