April 2, 201511 yr Im practicing my function paramter arguments input for example <?php function expire($day = 0) { if (!is_int($day)) { throw new Exeption('Error here.'); } return (60 * 60 * 24 * $day); } Or should i use <?php function expire($day = 0) { if (!isset($day) || empty($day) || is_null($day) || is_array($day) || is_bool($day)) { throw new Exception('Error here.'); } return (60 * 60 * 24 * $day); } Which is better?
May 3, 201511 yr Is this a trick question? . The first one with Exception spelt correctly as you are doing unnecessary checks in the second. $day is always set so you don't need isset is_int makes checking is_array, is_bool, is_null and empty redundant The first one is easier to read and maintain
Create an account or sign in to comment