..oO(Bill H)
>I have the same version of php running on our linux server as I have
on my local xampp runing under windows. While working yesterday a
piece of code I wrote just wouldn't work on the server, but ran fine
under xampp. The code in question opened a file and reads in the
contents line by line using a construct similar to this:
if ($line != "")
{
$xmlString .= "<setup value\"$line\" />\n";
}
Hint: HTML and XML also allow single quotes:
$xmlString .= "<setup value='$line'/>\n";
>After about 15 minutes of trying to figure out why it wasn't working
(the servers php error was mixed in the xml output and truncated) I
learned that on the server I had to have a line:
$xmlString = "";
before the routine, yet on the xampp one I didn't need it.
In clean and reliable code you _do_ need it.
>So I am
wondering, what option is either enabled or disabled to cause me to
have to declare the variable before using it?
You don't have to declare variables, but you have to initialize them
before you want to use them. These two assignments are equivalent:
$foo .= $bar
$foo = $foo.$bar
But if $foo doesn't exist yet, you'll get an E_NOTICE error on the first
call (at least if the error reporting is configured properly). That's
why you should initialize it beforehand:
$foo = '';
....
$foo .= $bar;
This will work without problems.
On the development machine make sure you have these directives in your
php.ini:
display_errors = on
error_reporting = E_ALL|E_STRICT
This will show you all problems while developing. Using an uninitialized
variable as in your code above definitely _is_ a problem that should be
fixed.
Of course on the production server display_errors should be off for
security reasons.
Micha