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

From: Date: Thu, 01 Apr 2021 09:45:34 +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-113899@lists.php.net to get a copy of this message
Le 01/04/2021 à 10:50, Olle Härstedt a écrit :
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
Hello, I don't know about the original motivations either, but at work we mostly use to force IDEs to understand types where PHP can't enforce them, due to its highly dynamic nature and lacks of generics. Most of our assert usage as like this: \asset($foo instanceof Bar); We never enable those on production, we have assert() calls pretty much everywhere and they don't serve any other purpose than being explicit for the code readers and IDE and we use them for debugging purpose: it raises exceptions for developer preventing them to proceed further until they fixe the bugs, but they don't break the production. Regards, -- Pierre

« previous php.internals (#113899) next »