Re: Why is assert limited to a debugging feature only?

From: Date: Thu, 01 Apr 2021 09:13:55 +0000
Subject: Re: Why is assert limited to a debugging feature only?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-113898@lists.php.net to get a copy of this message
On Thu, Apr 1, 2021 at 10:50 AM Olle Härstedt <olleharstedt@gmail.com>
wrote:

> 2021-04-01 10:24 GMT+02:00, Arnold Daniels <arnold.adaniels.nl@gmail.com>:
> > Hi,
> >
> > The documentation of assert
> > ([
> https://php.net/assert)](https://www.php.net/manual/en/function.assert.php
> ))
> > states that's debugging only. This is further enforced by php.ini flags
> to
> > disable assertions in production.
> >
> > Why are the use cases of this feature being limited to debugging? We can
> see
> > from the popularity of user-space assertion libraries, like
> > [webmozart/asset](https://packagist.org/packages/webmozart/assert) and
> > [beberlei/assert](https://packagist.org/packages/beberlei/assert), that
> > there is a need for runtime assertions.
> >
> > [Arnold Daniels - Chat @
> > Spike](https://spikenow.com/r/a/?ref=spike-organic-signature&_ts=yux2k)
>      [yux2k]
>
> Dunno about the motivation of the implementors, but usually assertions
> are used for internal invariants and mental checks while exceptions
> should be used for interaction with the outside world (database
> errors, user input errors etc). If you follow this, an assert error
> will never be useful for a user, it will always be an "internal
> error", and that's why it can (should?) be disabled in production.
>
> Olle
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
Hi,

I agree with Olle's explanation (and am indeed using assert() that way).
Also note that both linked libs throw InvalidArgumentException
(subclasses of), so not the same kind of "assertions" (despite the name).

Regards,

-- 
Guilliam Xavier


Thread (5 messages)

« previous php.internals (#113898) next »