php undeclared variable behavior differences between IIS and Apache

We have been recently switching over from apache to IIS and we are having problems with undeclared variables.

stuff like  
 //$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?
Who is Participating?
Ray PaseurConnect With a Mentor Commented:
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.
Lukasz ChmielewskiConnect With a Mentor Commented:
Why not using this (from an example:

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.

Vimal DMSenior Software EngineerCommented:

 - 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

Ray PaseurCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.