Solved

php undeclared variable behavior differences between IIS and Apache

Posted on 2011-03-01
5
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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 110

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

737 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