Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- What option would cause this to happen?
September 25, 2008, 9:26 am
rate this thread
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";
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. So I am
wondering, what option is either enabled or disabled to cause me to
have to declare the variable before using it?
Re: What option would cause this to happen?
Hint: HTML and XML also allow single quotes:
$xmlString .= "<setup value='$line'/>\n";
In clean and reliable code you _do_ need 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
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
Of course on the production server display_errors should be off for