From: admin at sellchain dot com
Operating system: Windows Server 2003
PHP version: 5.0.5
PHP Bug Type: Scripting Engine problem
Bug description: 'Cannot use string offset: Multi-Dimensional Array gives
error if not init.
Description:
------------
When using PHP to build a multi-dimensional array, the first 5 days, this
code worked fine. Suddenly, PHP got picky, and decided it shouldn't work
anymore.
# Because i declare $myp to become empty, (because this $myp is put into a
loop), I want the array to be empty next time around. So I declared it
$myp='' before it starts. This worked fine for a few days, I have been
testing this inside and out. All of a sudden FOR NO REASON, it just starts
telling me this error. ''Cannot use string offset as an array site'' Hmm?
Well I did manage to fix it, by declaring $myp[0][0]='' instead of
$myp='', however it seems like a really weird bug, because it decided to
jump at me 5 days after usage. Code examples below. Maybe you guys should
look into it.
Reproduce code:
---------------
<?
$myp='';
$myp=BuildAMultiArray(0,0,"test");
$GTIN = $myp[0][0];
echo $GTIN;
function BuildAMultiArray($l1, $l2, $str) {
$built[$l1][$l2] = $str;
return $built;
}
?>
Expected result:
----------------
test
Actual result:
--------------
CODE THAT FIXED IT:
<?
$myp[0][0]='';
$myp=BuildAMultiArray(0,0,"test");
$GTIN = $myp[0][0];
function BuildAMultiArray($l1, $l2, $str) {
$built[$l1][$l2] = $str;
return $built;
}
?>
--
Edit bug report at http://bugs.php.net/?id=35285&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35285&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=35285&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=35285&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35285&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35285&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35285&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35285&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35285&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35285&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35285&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=35285&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=35285&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35285&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35285&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35285&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35285&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35285&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35285&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35285&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35285&r=mysqlcfg