php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14066 Can't suppress warnigns on accessing invalid string offset
Submitted: 2001-11-15 02:33 UTC Modified: 2003-04-25 11:07 UTC
Votes:4
Avg. Score:4.0 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: mfischer at guru dot josefine dot at Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.0CVS-2001-11-15 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-11-15 02:33 UTC] mfischer at guru dot josefine dot at
When setting error_reporting(E_ALL) the following occurs:

<?
error_reporting(E_ALL);

$foo = array(); echo $foo[0] . "\n"; // <-- warning
$foo = array(); echo @$foo[0]. "\n"; // <-- no warning

$foo = "foo"; echo $foo{3} . "\n"; // <-- warning
$foo = "foo"; echo @$foo{3}. "\n"; // <-- still warning
?>

The last line should not emit a warning.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-02 17:01 UTC] phanto@php.net
'isset($foo[0])' issues a warning too if $foo is an emtpy string.
 [2001-12-02 17:04 UTC] mfischer@php.net
Btw, this breaks BC:

[chroot] mfischer@ficken:~/isrc/cvs/php4/Zend$ php -v
4.0.6-dev
[chroot] mfischer@ficken:~/isrc/cvs/php4/Zend$ php -q
<? error_reporting(E_ALL); $foo = ''; isset($foo[2]);?>
[chroot] mfischer@ficken:~/isrc/cvs/php4/Zend$ 

and with RC4:

mfischer@ficken:~/isrc/cvs/php4/Zend$ php -v
4.1.0RC4
mfischer@ficken:~/isrc/cvs/php4/Zend$ php -q
<? error_reporting(E_ALL); $foo = ''; isset($foo[2]);?>
<br>
<b>Warning</b>:  Uninitialized string offset:  2 in <b>-</b> on line <b>1</b><br>
-(1) : Warning - Uninitialized string offset:  2
mfischer@ficken:~/isrc/cvs/php4/Zend$

Marking as critical.
 [2001-12-02 17:06 UTC] mfischer@php.net
One more, this change happened in Zend/zend_execute.c line 103.

 [2002-03-03 17:28 UTC] derick@php.net
It's not a bug, $foo{3}. "\n" is done before the @, so that displays the error.
so I'm closing this, this works BTW:
$foo = "foo"; echo @($foo{3}. "\n");

Derick
 [2002-03-03 17:35 UTC] mfischer@php.net
I'm not satisfied with this answer :-)

Why does it work with arrays but not with strings (and, bert, yeah I know they aren't the same).

Just because "it's strings here" doesn't legitimate that a warnings is thrown. Using your suggestion is rather cumbersome.

Is it an implemention issue? Can it be solve to be less long winded?

"it is"

a bug imho :)
 [2002-03-03 17:35 UTC] mfischer@php.net
I'm not satisfied with this answer :-)

Why does it work with arrays but not with strings (and, bert, yeah I know they aren't the same).

Just because "it's strings here" doesn't legitimate that a warnings is thrown. Using your suggestion is rather cumbersome.

Is it an implemention issue? Can it be solve to be less long winded?

"it is"

a bug imho :)
 [2002-03-03 17:47 UTC] derick@php.net
It's an engine thing, and can really not be fixed. The accessing of the {3} is done after the END_SILENCE op at the CONCAT op.
I'll mark it as suspended for now.
 [2003-04-25 11:07 UTC] sniper@php.net
Since we now have this 'wont fix' status, let's use it. :)

 [2003-11-18 09:47 UTC] php at pleaseletusknow dot com
This error, in latest PHP versions, only occurs when your trying to treat a plain variable as an array.

In most occasions you can get round this by adding in an isArray check before you try to use the var as an array.

For example;

Problem:
if (isset($parameter['align'])) { echo 'moo'; } // error: Uninitialized string offset 

Solution:
if (!isarray($parameter)) { $parameter = array(); }
if (isset($parameter['align'])) { echo 'moo'; }

So your basically setting an empty array in place of an empty variable.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC