Forum Moderators: coopster
Thanks,
Ryan
are these warnings showing in the page?
as coop confirmed, just use
[php.net...]
unless there is something we are not understanding
<?
$error[] = "Some error here";
foreach($error as $k=>$v){
echo $v."<br>";
}
?>
This just echo's the letter "S" (the first letter in the error message), I think it is because although I am attempting to set it into an array, its setting it as a scalar variable because i didn't initiate the array. If it add
<?
$error = array();continue code...
Then it works, because it sets the variable type as an array. Now I know that the correct thing to do would be to code stricter and actually instantiate my variables with the correct data types, but I have the whole thing working on 1 server (which allows this), and now that I am trying it on another server it wont set the variables the same. Any ideas?
Thanks,
Ryan
I think it is because although I am attempting to set it into an array, its setting it as a scalar variable because i didn't initiate the array.
No, that is not the case as PHP allows you to Create/modify with square-bracket syntax [php.net]. If the array does not yet exist it will be created.
Which version of PHP is running on the server that is not working correctly?
I don't believe register_globals would have anything to do with it. To find out, you could always dump the variable prior to using it here to see if it exists in memory already. You'll get an error if it doesn't exist.
<?php
print '<pre>'; [b]var_dump [php.net]($error); print '</pre>';
$error[] = "Some error here";
foreach($error as $k=>$v){
echo $v."<br>";
}
?>
$error = "hello";
$error[] = "Some error";
The fix is to either
unset($error);
or
$error = array();
before reusing it as an array.
I ran across this a couple of months ago, and verified that it caused problems on both my shared hosting 4.7 LAMP and my 5.2.something WAMP home game.