|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-02 19:28 UTC] mpb dot mail at gmail dot com
Description: ------------ The error control operator '@' fails to suppress (some) "Uninitialized string offset" notices. See example for details. The problem also occurs on with PHP 4.4.x. Reproduce code: --------------- <?php error_reporting (E_ALL | E_NOTICE); $x = 'test'; $x[4]; // No notice at all - compiler optimization?? @$y = $x[4]; // Notice supressed. @'a' == $x[4]; // Notice NOT supressed - but it should be. @$x[4] == 'a'; // Notice NOT supressed - but it should be. (@$x[4]) == 'a'; // Notice NOT supressed - but it should be. (@($x[4])) == 'a'; // Notice NOT supressed - but it should be. @($x[4]) == 'a'; // Notice NOT supressed - but it should be. @($x[4] == 'a'); // Notice supressed. print "Done!\n"; ?> Expected result: ---------------- Done! Actual result: -------------- Notice: Uninitialized string offset: 4 in /home/build/test.php on line 7 Notice: Uninitialized string offset: 4 in /home/build/test.php on line 8 Notice: Uninitialized string offset: 4 in /home/build/test.php on line 9 Notice: Uninitialized string offset: 4 in /home/build/test.php on line 10 Notice: Uninitialized string offset: 4 in /home/build/test.php on line 11 Done! PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 20:00:01 2025 UTC |
While operator precedence explains the notice generated by line 7 of my original example, it does not explain the other lines. Here is a simpler example clearly showing this bug has nothing to do with operator precedence. The notices in line 11 and 14 should be suppressed - but they are not. Compare lines 11 and 14 to lines 12 and 15 respectively. Reproduce code: --------------- <?php error_reporting (E_ALL | E_NOTICE); $s = 'test'; $a = array ('t', 'e', 's', 't'); if ( $s[4] ); // line 8, not suppressed if ( $a[4] ); // line 9, not suppressed if ( @ $s[4] ); // line 11, not suppressed if ( @ $a[4] ); // line 12, suppressed if ( @ ( $s[4] ) ); // line 14, not suppressed if ( @ ( $a[4] ) ); // line 15, suppressed if ( @ ( $x=$s[4] ) ); // line 17, suppressed if ( @ ( $y=$a[4] ) ); // line 18, suppressed print "Done!\n"; ?> Expected result: ---------------- Notice: Uninitialized string offset: 4 in /borg/ripple/parke/test4.php on line 8 Notice: Undefined offset: 4 in /borg/ripple/parke/test4.php on line 9 Done! Actual result: -------------- Notice: Uninitialized string offset: 4 in /borg/ripple/parke/test4.php on line 8 Notice: Undefined offset: 4 in /borg/ripple/parke/test4.php on line 9 Notice: Uninitialized string offset: 4 in /borg/ripple/parke/test4.php on line 11 Notice: Uninitialized string offset: 4 in /borg/ripple/parke/test4.php on line 14 Done!