|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-02-12 22:58 UTC] torben at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
The document on migration from PHP2 to PHP3 says that $var is no longer equivalent to $var[0], but I just spent some hours finding out that the reason for "Illegal string index" errors in the following code fragments seems to be that once a scalar variable is set, it's an error to try to re-use it as an array variable. I imagine that unset($var) between the various lives of a variable would be a workaround, but loose typing of variables in PHP as opposed to C ($a="string"; $a=3.4; etc) tends to make this a surprise. If you could just mention this in the docs where you're talking about variable types and/or arrays and/or the PHP2-->3 doc, maybe this could save someone else some head scratching. You might not be surprised to hear that this behavior is the same in PHP 3.0.9, 3.0.7, and in fact 3.0RC4. In the code that follows, qry() is just a wrapper for mysql_query(): $q="select * from skedb where uid = ".$id; $res=qry($q,"Getting values for current schedule"); /* imtg1 is an integer here: */ $imtg1=mysql_Result($res,0,"mtg1"); $qq="select md from leave where uid = "; if($imtg1>0) { $q=$qq.strval($imtg1); /* still an integer, but */ /* finished using it. Now want an array of similar name.*/ $res=qry($q,"Getting MDs on leave on Monday"); $im1=mysql_NumRows($res); $i=0; while($i<$im1) { /* following generates an illegal string index error */ /* but interestingly, not until $imtg1[3] access */ /* attempted */ $imtg1[$i]=mysql_Result($res,$i,0); $i++; } } old_function qry $a,$b ( global $db,$conn; $r=mysql_query($a,$conn); if(!$r) { echo "Problem with database. Check server status."; echo "<br>Was in section <i>$b</i><br>"; echo "<p>Query was: $a<p>"; exit; } return($r); ); By the way, thanks for some truly wonderful glue between Apache & MySQL!!