Bug #1585 Updated: Arrays & scalar variables of same name cant coexist
| From: | Bug Database | Date: | Sat, 12 Feb 2000 21:58:04 +0000 |
| Subject: | Bug #1585 Updated: Arrays & scalar variables of same name cant coexist | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-15476@lists.php.net to get a copy of this message | ||
ID: 1585
Updated by: torben
Reported By: al52x@nih.gov
Status: Closed
Bug Type: Documentation problem
Assigned To:
Comments:
There is now a note in the docs about this, but the code below isn't doing
quite what you think and so you're hitting this problem.
Background: the behaviour of implicit conversion between array and string
types using [] is undefined. For instance:
<?php
$a = "This is a test";
$a[0] = 'X';
echo $a; // should this work?
?>
In this example, should 'echo $a' produce 'Xhis is a test', or
'Array'? The
assignment (knowing that $a is a string) could mean either.
This applies to your example because when you run this:
/* imtg1 is an integer here: */
$imtg1=mysql_Result($res,0,"mtg1");
...$imtg1 is *not* an integer; it's a string holding a numeric value.
Apparently, it's only 3 chars long, so when you attempt to assign to
$imtg1[3], you've gone off the end of the string.
The easiest workaround is simply to use another variable there.
Full Bug description available at: http://bugs.php.net/?id=1585