Re: [PHP-DEV] Avoiding "Undefined index" notices

2011-04-11 Thread Etienne Kneuss
On Apr 11 12:08:15, Todd Ruth wrote: > I'm not arguing whether the following code fragment is good > or bad (it's certainly less than ideal), but given the recent > threads, I thought I'd show how I feel I've been encourage by > php to code: > > $x = array(); > $y = 'something'; > $temp =& $x[$

Re: [PHP-DEV] Avoiding "Undefined index" notices

2011-04-11 Thread Etienne Kneuss
On Apr 11 14:14:40, Matt Wilson wrote: > Something I've been doing for a long time is similar, but in my opinion a > much better practice. > > function coalesce(&$val, $ifnull = false) > { > return empty($val) ? $ifnull : $val; > } > > Add whatever restrictive logic you wish here, if empty

Re: [PHP-DEV] Avoiding "Undefined index" notices

2011-04-11 Thread Matt Wilson
Something I've been doing for a long time is similar, but in my opinion a much better practice. function coalesce(&$val, $ifnull = false) { return empty($val) ? $ifnull : $val; } Add whatever restrictive logic you wish here, if empty() isn't good enough for your purposes. $_GET['might

[PHP-DEV] Avoiding "Undefined index" notices

2011-04-11 Thread Todd Ruth
I'm not arguing whether the following code fragment is good or bad (it's certainly less than ideal), but given the recent threads, I thought I'd show how I feel I've been encourage by php to code: I'm not sure where (if anywhere) that technique is documented or even if it should be documented,