Re: [PHP] should basic data validation go outside a function or inside?
Brad Pauly wrote: should basic data validation come before a function call or be performed within the function? I would do the validation inside the function. This avoids repeating the validation everywhere the function is called. It also makes the function more self-contained. It expects a certain input and complains, or returns false, if it doesn't get it. yes, and of course shouldnt every function check it parametres before proceeding? -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] should basic data validation go outside a function or inside?
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
Re: [PHP] should basic data validation go outside a function or inside?
On Wed, 10 Nov 2004 11:00:12 -0800, Chris W. Parker [EMAIL PROTECTED] wrote: should basic data validation come before a function call or be performed within the function? advice type=record status=b0rken value=Benchmark them both and see which way is faster. then post back and tell us. :) / -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should basic data validation go outside a function or inside?
On Wed, 10 Nov 2004 11:00:12 -0800, Chris W. Parker [EMAIL PROTECTED] wrote: 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? I would do the validation inside the function. This avoids repeating the validation everywhere the function is called. It also makes the function more self-contained. It expects a certain input and complains, or returns false, if it doesn't get it. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php