Re: Why not use assertions for input validation?

From: Date: Tue, 13 Apr 2004 20:37:33 +0000
Subject: Re: Why not use assertions for input validation?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183262@lists.php.net to get a copy of this message
* Thus wrote Fraser Campbell (fraser@georgetown.wehave.net): > Hi, > > What is it about assertions that makes them unsuitable for production use? - For one, if assert() eveluates code like eval() does, there is very poor performance hit using it and a lot of overhead just to do simple statements that can easily be caught with an if statement. - It isn't desined to replace the if statement. - And with the example used in the article mentioned: assert("ereg($regex, $email, $parts); /* Invalid email address: $email */"); If assert.active is off, your validation is never checked. A more appropriate use for assert() would to be to prevent a E_WARNING/E_ERROR to be thrown for the regex: assert('empty($email); /* email was empty */') if (!ereg($regex, $email, $parts) ) { ... So in the development and QA process if that condition ever arises, then it can be fixed. So when the code is in production, we are guaranteed that never will there be a 'E_WARNING: second paramter is empty' issued. Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#183262) next »