Pattern etc to reduce duplicated validation?

From: Date: Thu, 27 Mar 2008 09:36:45 +0000
Subject: Pattern etc to reduce duplicated validation?
Groups: php.general 
Request: Send a blank email to php-general+get-272155@lists.php.net to get a copy of this message
Hi All I seem to be writing a lot of this: //======== SCRIPT ========= $var = $_POST['var']; // validate $var $foo = new foo; $foo->setBar($var); //======== CLASS ========== class foo {
    public function setBar($var) {
        // validate $var
    }
} As you can see, the "issue" is that I am validating the input in my script, and then again in my class... surely unwanted duplication!? Obviously (I think!), I need to be validating at the level of my class, so does anyone have a pattern / strategy to help ease the pain... a way of using the validation in the class to validate the script and return meaningful errors to the user?? Throwing errors and forcing the script to catch them perhaps? I have tried a few validation classes etc and they have not really addressed this issue. Perhaps I should just live with it and get on with it! :) Many thanks for your help, David

« previous php.general (#272155) next »