On 18 Jul 2016 17:18, "Remi Collet" <Fedora@xxxxxxxxxxxxxxxxx> wrote:
>
> Le 18/07/2016 à 12:59, James Hogarth a écrit :
>
> > * Runtime (not test) PHP code SHOULD not use assert() for runtime checks
>
> IMHO, having "assert" on production code is valid.
>
> As these "assert" are just no-op (exactly as in C code for NDEBUG build)
>
But they are not no-op ... They throw an exception on false which then can alter runtime behaviour (eg if using to verify a variable type).
> They are helpers for developers to detect bad run case without any
> impact on production.
>
> In PHP 5, assert have a big performance impact, so are mostly never
> used, while they have a 0 cost in PHP 7.
>
Well I have one example that I've directly encountered in packaging of them being used... It's hard to say how many applications might be using them, and the existing PHP5 had assert.active enabled in options.
And it's only zero cost in PHP7 as they get compiled out with the present rawhide options.
> In your example, "is_bool" is perhaps only there for cleaner code
> (as 0/1 values are not bool, but will work as expected)
>
>
Well those will still be seen as boolean true false on tests in PHP ... And if you check the php-saml code you'll see it's actually being used to verify that it's true or false as understood PHP for a setStrict function before acting on that value for whether a strict validation should be used or not.
_______________________________________________ php-devel mailing list php-devel@xxxxxxxxxxxxxxxxxxxxxxx https://lists.fedoraproject.org/admin/lists/php-devel@xxxxxxxxxxxxxxxxxxxxxxx