Reply LinkBack Thread Tools Search this Thread
Old 19-09-2006, 12:03   #1 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
php notices (undefined variables)

getting loads of notices regarding undefined variables, and i have been doing this to get rid:

PHP Code:
if (isset($_GET['variable']))
{
  
$variable$_GET['variable'];
}
else
{
  
$variable"";


just wondered if this was the correct way? (variables are coming from url strings and cannot be set in the code)
  Reply With Quote
Old 19-09-2006, 12:27   #2 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
$variable = isset($_GET['variable']) ? $_GET['variable'] : null;
  Reply With Quote
Old 29-09-2006, 23:08   #3 (permalink)
aristoworks
<insert clever title>
 
Join Date: Sep 2006
Location: Nashville, TN USA
Posts: 17
Send a message via AIM to aristoworks
or.

You could always just turn the errors off if you don't want to be bothered.

error_reporting(0);
  Reply With Quote
Old 30-09-2006, 06:33   #4 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 828
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Quote:
Originally Posted by aristoworks
You could always just turn the errors off if you don't want to be bothered.

error_reporting(0);
Personally I think the errors should always be reported as it will help maintain cleaner code and will notify you otherwise. I'd recommend going with d3mcfadden's advice using the Ternary Operator. Nice, clean, simple.

- Mike
  Reply With Quote
Old 30-09-2006, 06:45   #5 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,713
if my car makes weird noises i could always turn the radio up but id pay in the long run
  Reply With Quote
Old 30-09-2006, 08:33   #6 (permalink)
aristoworks
<insert clever title>
 
Join Date: Sep 2006
Location: Nashville, TN USA
Posts: 17
Send a message via AIM to aristoworks
.

Just offering a simple solution. Obviously it's best to fix the problem BUT if he's got a simple site and incorporates an older script and the only errors he gets is a bunch of undefined variables technically there's no harm with turning those errors off.

It's important to understand how PHP's built in error reporting works anyways - I'd never let a client site go live fully opened up as naturally there may be a bump or 2 in the road. Build a custom error_log scheme and that will let you know whats wrong and not make your client look like an amature.
  Reply With Quote
Old 30-09-2006, 09:17   #7 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 828
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Quote:
Originally Posted by aristoworks
Just offering a simple solution.
Absolutely and it's always good to have a choice, no criticism in my post was intended.

- Mike
  Reply With Quote
Old 30-09-2006, 10:36   #8 (permalink)
RJP
Registered User
 
RJP's Avatar
 
Join Date: Sep 2006
Location: Calgary
Posts: 7
Just to clarify... the reports you are getting about undefined variables are "NOTICES"... which is the lowest level of reports. They are "things that you oughtta know", but they don't really have any impact on your script.

You can change the specified reporting level to not display NOTICE reports, but still report "warnings" and "errors". This will get rid of these not so important messages, but will still help you when you have real problems.

-Ryan
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8