Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113899 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19246 invoked from network); 1 Apr 2021 09:47:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Apr 2021 09:47:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6DFF1804D3 for ; Thu, 1 Apr 2021 02:45:43 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 1 Apr 2021 02:45:42 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 6652D5101324 for ; Thu, 1 Apr 2021 09:45:36 +0000 (UTC) To: internals@lists.php.net References: Message-ID: <81ecea3e-271e-6767-a7cb-4c56829412b0@processus.org> Date: Thu, 1 Apr 2021 11:45:34 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] Why is assert limited to a debugging feature only? From: pierre-php@processus.org (Pierre) 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