should basic data validation go outside a function or inside?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi.

call me stupid but i can't decide which option is better (actually don't
call me stupid because it will hurt my feelings and i might cry). and
having said that, maybe neither option is better than the other?
whatever the answer, i just want some outside input on this because for
some reason my brain is getting caught up on it and it's bothering me.

should basic data validation come before a function call or be performed
within the function?

example of validation outside the function:

<?php

  if(is_numeric($this->id) && !empty($this->id))
  {
    $new_number = my_function($this->id);
  }
  else
  {
    $new_number = false;
  }

?>

example of validation inside the function:

<?php

  function my_function($number)
  {
    if(is_numeric($number) && !empty($number))
    {
      // perform some calculations
    }
    else
    {
      return false;
    }
  }

  $new_number = my_function($this->id)

?>


thanks,
chris.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux