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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php