473,387 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What option would cause this to happen?

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
2 1469
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
..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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: Brent Eamer | last post by:
function SetDefaultDate() { d = new Date(); return d; } ........ <TD align=left> Start Date: </TD> <TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"...
10
by: linq936 | last post by:
Hi, I have many assert() call in my code, now I am considering to replace them with exception. The reason I want to do this change is that with the program going bigger and bigger, it is hard to...
19
by: What-a-Tool | last post by:
I have a school project (ASP) in which I have to call three different ASP pages from three different and identical (except for the form "action", obviously) HTM pages. This I have no problem with....
10
by: Nathaniel Branden | last post by:
Hello. This isn't really an Access question. I just want to know whether Tony Toews is retarded. In that vain, I have pasted down his last thirty or so posts for someone out there to respond. ...
20
by: PC Datasheet | last post by:
How can the label for a checkbox and the labels for the options in an option group be addressed? When a checkbox gets the focus, Access draws a dotted box around the label. When an option group...
2
by: Steven T. Hatton | last post by:
I'm carrying on a discussion in a nother context regarding the value and usefulness of data types. Part of that discussion has to do with how data types might be implemented in the language...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
6
by: Arthur | last post by:
Hello. How might it be possible to change where a form action is directed based on a selected option. For example I have this: <FORM METHOD = "post" ACTION = ""> And a drop down such as
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.