php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39018 Error control operator '@' fails to suppress "Uninitialized string offset"
Submitted: 2006-10-02 19:28 UTC Modified: 2008-03-08 11:42 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mpb dot mail at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.3 OS: Gentoo Linux
Private report: No CVE-ID:
 [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!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-03 19:57 UTC] iliaa@php.net
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

Operator precedence is working against you in this instance. 
The operation involving offset operation is before before the 
error blocking operator is considered.
 [2006-10-04 21:47 UTC] mpb dot mail at gmail dot com
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!
 [2008-03-08 11:42 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC