Monday, 15 February 2010

php - When to validate/sanitize the arguments of an overridden method? -



php - When to validate/sanitize the arguments of an overridden method? -

what can tell validating/sanitizing arguments of overridden method in class?

if have like

class parentclass { public function originalmethod($id) { if(is_numeric($id) && (int) $id > 0) { // utilize $id } } }

and subclass overrides method

class childclass extends parentclass { public function originalmethod($id) { parent::originalmethod($id); // other stuff } }

my question is:

in cases proceed validation of method's arguments?

shouldn't expect/assume right validation has performed in parent method?

i've seen sometime code validation performed 1 time again (not in simple case 1 above).

would validate each time? never? under circumstances?

i utilize general guide line:

if base of operations function called in overridden function first statement, verification done in overridden function. in cases additional verifications need added in overridden function. unless base of operations function changes variables used verification used in overridden function. if base of operations function not called, have think verification; needs copied, extended or deleted (partly). if base of operations function called after overridden function (or not in beginning), verification might needed; other verifiction handled in base of operations function.

of course of study these guideline; exceptions can occur.

php validation oop sanitization method-overriding

No comments:

Post a Comment