By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

What option would cause this to happen?

P: n/a
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?

Bill H
Sep 25 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Bill H wrote:
$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?

Bill H
The difference is error reporting. Read all about it on the php website :-)

Floortje
Sep 25 '08 #2

P: n/a
..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
Sep 25 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.