Solved

php undeclared variable behavior differences between IIS and Apache

Posted on 2011-03-01
5
435 Views
Last Modified: 2012-05-11
We have been recently switching over from apache to IIS and we are having problems with undeclared variables.

stuff like  
<?php
 //$variable not declared yet;
 if($variable != 1) 'echo something';
?>

Open in new window


issues a notice but also doesn't run whats in the if statement.  In the previous environment this would still run.  I'm blaming this on IIS because i beleive the php versions are close if not the same.

I realize this is not exactly best practice but it would not be worth the effort to change all of our old code.  Is there something in the php ini file i can change that would make it handle undeclared variables differently?
0
Comment
Question by:brad0525
5 Comments
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 150 total points
ID: 35007442
Why not using this (from an example:
http://www.php.net/manual/en/function.error-reporting.php
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35007569
Hi,

You need to specify in you php.ini file that the system should not report warnings, the version of php points to may differ to the apache version hence the system is reporting the errors.

so display_errors = Off
on the live environment.

D
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 35008932
Hai,

 - What ever the version that you follow in PHP

 - it is perfectly, that the variable should have the at least the empty value

 - only than you can use that particular variable for any process

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 35011349
The default PHP installation is usually

error_reporting(E_ALL ^ E_NOTICE);

Try adding that to the top of your script.   It will let you use undefined variables as if they were NULL, FALSE or zero, depending on the loose typecasting that PHP provides.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35011368
And a sidebar note - you almost always want to do your development with error_reporting(E_ALL).  That way when you have a typographical error and you accidentally use an undefined variable, you will get a Notice instead of a silent substitution that is much harder to debug!

Best of luck with it, ~Ray
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now