[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

php undeclared variable behavior differences between IIS and Apache

Posted on 2011-03-01
5
Medium Priority
?
486 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 600 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 111

Accepted Solution

by:
Ray Paseur earned 1400 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 111

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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 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