[FX.php List] PHP Notices OK?

Michael Layne fx at 9degrees.com
Wed Dec 12 10:07:57 MST 2007


I also understand that while NOTICES are not pure evil or evidence of  
something terrible, if I see them, I am compelled to correct the  
problem.  Obviously SOMETHING is not 100%.

I don't know if there is a better way of doing this, but I tend to do  
the following whenever I have a variable that may not always be set:

isset($_REQUEST['variable']) ? $variable = $_REQUEST['variable'] :  
$variable = '';

Then for the rest of my code, I can just use' $variable'

BTW - I've been asked about it before, so I'll go ahead and mention  
that the above is shorthand(is that the term?) for the following:

if (isset($_REQUEST['variable])) {
	$variable = $_REQUEST['variable'];
	} else {
	$variable = '';
}

HTH,

Michael

On Dec 12, 2007, at 11:59 AM, Steve Winter wrote:

> Hi Trish,
>
> Would doing
>  foreach($_POST as $key => $value)
>    $ordersQuery->AddDBParam($key, $value);
>
> Not have worked for some reason...??
>
> The other thing that I have done with checkboxes is to set a hidden  
> field,
> with the same name just before the checkbox, with value  
> 'defaultValue', then
> when looping through I can not save those by doing
>
>  foreach($_POST as $key => $value) {
>    if($value != 'defaultValue')
>      $ordersQuery->AddDBParam($key, $value);
>  }
>
> Cheers
> Steve
>
> -----Original Message-----
> From: fx.php_list-bounces at mail.iviking.org
> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of VanBuskirk,
> Patricia
> Sent: 12 December 2007 16:50
> To: FX.php Discussion List
> Subject: RE: [FX.php List] PHP Notices OK?
>
> I have had a heck of a time with undefined variable errors, especially
> when they are in checkboxes or radio buttons.  I had to do a statement
> such as:
>
> $checkBoxes =
> array 
> ('BasicSvc_Features','Instrument','Number_800','Calling_Card','COS'
> ,'Auth_Code','Voice
> Mail 
> ','VM_Passcode_Reset','Meet_Me','Cellular_Service','SCV','Video_Conf
> erence 
> ','Networking','DSL','Cable_Internet','Access_System','Budget_Info
> _Change','Information_Change','Wiring', 'Estimate');
>
> foreach($checkBoxes as $checkBox) {
> 	if(isset($_POST[$checkBox])) {
> 		$ordersQuery->AddDBParam($checkBox, $_POST[$checkBox]);
> 		}
> 	}
>
> Trish
>
> -----Original Message-----
> From: fx.php_list-bounces at mail.iviking.org
> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Jonathan
> Schwartz
> Sent: Wednesday, December 12, 2007 11:40 AM
> To: FX.php Discussion List
> Subject: RE: [FX.php List] PHP Notices OK?
>
> OK. That's fair.
>
> To be honest, I never knew about these things since I have developed
> on my own server and Notices are turned off....until now. ;-)
>
> One step further...my notices appear to be of the Undefined Variable
> type.  I did see your suggestion from last week, to add in
> if(isset($variable)) rather than "surprise" PHP when an undeclared
> variable appears.  Is another alternative to simply declare the
> variable at the top of he page?  If so, how is that best done?
>
> Thx
>
> Jonathan
>
> At 4:15 PM +0000 12/12/07, Steve Winter wrote:
>> Hi Jonathan,
>>
>> Well I guess that one is rather 'up to the conscience of the  
>> individual
>> church goer' ;-)
>>
>> For me, personally, no, it's not acceptable, as it means that  
>> something
>> isn't 100% correct, which means you can't be 100% sure that when it
> runs on
>> a client server, or you move it from one server to another, that it
> will
>> still behave correctly...
>>
>> My staging server has every level of error reporting possible turned
> on, and
>> when that gives no messages, notices, errors, or unexpected twitches,
> then I
>> feel reasonably sure that my code will run at the very least, on
> similar
>> versions of PHP, if not on all...
>>
>> My 2p worth...
>>
>> Cheers
>> Steve
>>
>> -----Original Message-----
>> From: fx.php_list-bounces at mail.iviking.org
>> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Jonathan
> Schwartz
>> Sent: 12 December 2007 16:05
>> To: FX.php Discussion List
>> Subject: [FX.php List] PHP Notices OK?
>>
>> Hi Folks,
>>
>> Is it acceptable for a solution to produce NOTICES (for undefined
>> variables) and then essentially hide them by turning off
>> error_reporting NOTICES?
>>
>> Or at minimum, should the solution run clean without notices?
>>
>>
>> Thx
>> --
>> Jonathan Schwartz
>> Exit 445 Group
>> jonathan at exit445.com
>> http://www.exit445.com
>> 415-381-1852
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
> -- 
> Jonathan Schwartz
> Exit 445 Group
> jonathan at exit445.com
> http://www.exit445.com
> 415-381-1852
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list