Re: Why not use assertions for input validation?
| From: | William Lovaton | Date: | Tue, 13 Apr 2004 19:20:22 +0000 |
| Subject: | Re: Why not use assertions for input validation? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183258@lists.php.net to get a copy of this message | ||
Well, what ever I say might be wrong because I'm not an expert in
assertions.
First of all, I didn't know that PHP had assertions... so, cool! :-)
Second, I know that assertions are used in non-interpreted languages,
like C for example, and it gives a way to make some kind of debugging
when the code is compiled in "debugging" mode. When a given condition
evaluates to true it will "assert" an specific message or situation.
But all the assertions are deactivated when the program is compiled for
a production environtment.
So, you can have debbuging code in your program with assertions and that
won't affect the performance or behaviour when it is compiled for a
production environment.
Remember, I might be wrong or inaccurate. But I agree that it is not a
good idea to use assertions to validate input data or for normal
operations.
-William
PS. Could you post a link to that article?
El mar, 13-04-2004 a las 13:58, Fraser Campbell escribió:
> Hi,
>
> An article was recently published in Linux Journal entitled Real-World PHP
> Security.
>
> Assertions are mentioned in the article as a way to enforce validity of input.
> I didn't even realize that php had assertions so I investigated a little
> further ...
>
> PHP docs on the assert function
> (http://www.php.net/manual/en/function.assert.php) states "Assertions should
> not be used for normal runtime operations like input parameter checks" which
> contradicts the Linux Journal article. An article in the user contributed
> notes (http://www.sitepoint.com/article/1008/) also states not to use
> assertions in production.
>
> What is it about assertions that makes them unsuitable for production use?
>
> Thanks!
> --
> Fraser Campbell <fraser@wehave.net>
> http://www.wehave.net/
> Georgetown, Ontario, Canada Debian GNU/Linux