[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] utf-8 ?
From:       Chris <dmagick () gmail ! com>
Date:       2009-04-30 22:54:09
Message-ID: 49FA2C11.2080701 () gmail ! com
[Download RAW message or body]


> The consensus seems to be that the proposed "ifset()" and "ifempty()"
> functions are more effort than they are worth. What I'd like to know
> is, why "empty()" still exists when every time I turn around, the
> mentors I turn to locally tell me not to use it, to use "isset()"
> instead. Because empty() doesn't work with zero. Anyone care to take
> a stab at that?

They serve different purposes and both work very well.

$form_errors = array();

// process form
foreach (array('name', 'email') as $field) {
   # Hey! someone hacked the form! This field is supposed to be there!
   if (!isset($_POST[$field])) {
     $form_errors[] = 'Field ' . $field . ' was missing';
     continue;
   }

   # The field is there but has no value.
   if (empty($_POST[$field])) {
     $form_errors[] = 'Field ' . $field . ' was empty';
   }
}

if (!empty($form_errors)) {
   echo 'there were errors in processing the form.<br/>';
   exit;
}

-- 
Postgresql & php tutorials
http://www.designmagick.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic