Warning when switch & reference are combined
| Bug #17997 | Warning when switch & reference are combined | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2002-06-26 11:25 UTC | Modified: | 2003-10-07 20:51 UTC |
|
||||||||||
| From: | Xuefer at 21cn dot com | Assigned: | ||||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 4CVS, 5CVS | OS: | All | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2002-06-26 11:25 UTC] Xuefer at 21cn dot com
let the sample code say the problem
<?
error_reporting(E_ALL);
$str1 = '.........$...';
$str = &$str1;
$l = strlen($str);
for ($i = 0; $i < $l; $i ++)
{
switch ($str{$i})
{
case '$':
$str = '123'; // change string
$i = -1; // set to -1, for next loop to be 0
$l = strlen($str); // u know what this do
break;
default:
echo $str{$i};
}
}
?>
-----------
result:
-----------
.........
Notice: Uninitialized string offset: 9 in d:\myfile\wwwroot\our-sky.com\test.php on line 19
123
how ever, if i change
$str = '123';
to:
$s = '123';
$str = &$s;
no wanning
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2002-07-23 16:45 UTC] hholzgra@php.net
[2003-08-10 18:12 UTC] helly@php.net
[2003-10-07 12:01 UTC] zeev@php.net
[2003-10-07 20:51 UTC] sniper@php.net