Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69637 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91433 invoked from network); 17 Oct 2013 15:51:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 15:51:35 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.45 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.45 mail-oa0-f45.google.com Received: from [209.85.219.45] ([209.85.219.45:53610] helo=mail-oa0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/B0-12663-68700625 for ; Thu, 17 Oct 2013 11:51:35 -0400 Received: by mail-oa0-f45.google.com with SMTP id i4so1797937oah.32 for ; Thu, 17 Oct 2013 08:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2JSwkMWcrqjnAuyD2nNQrnf6X3gr/WLU/GPTY5JWz1c=; b=kUHe1UtURF0KpSDINxQNR1ijqlr+5gRRQlWG0E17dpsv+Ndu01+eFrsLMHxwMloi+7 aij6uTy5CbWSohmjCo6ZfAwvf+3We9ZYkDchndhO3er1a5wgpw2EaoPiAcQR+oIsOih3 QC3HxlGb+2FqgpPp5B7dT+QShkjgZ3q0w8lYE9NGlsfRaGYVMgZErDQrq+I6+v589Vx4 hldNTKCN0y/kGD2l6Nk9Bz0bre2Shrs8KKwXnTw1KLIhGFFXUYg5KJe3gcVZIGSt5SIZ YFWqznQpv0b9Akag+xwsziclNLdiWyeY9QA40dKJBBzz+iGNUV3YZaaye/qwde5aD/yB m9lA== MIME-Version: 1.0 X-Received: by 10.182.85.167 with SMTP id i7mr2640385obz.60.1382025089595; Thu, 17 Oct 2013 08:51:29 -0700 (PDT) Received: by 10.182.54.112 with HTTP; Thu, 17 Oct 2013 08:51:29 -0700 (PDT) In-Reply-To: References: <525FC834.4060501@php.net> <1534105.bNC2os93J1@rofl> <525FDAC3.6060103@php.net> Date: Thu, 17 Oct 2013 17:51:29 +0200 Message-ID: To: J David Cc: Joe Watkins , PHP internals , Michael Wallner Content-Type: multipart/alternative; boundary=089e01536de8893e8604e8f1ca06 Subject: Re: [PHP-DEV] Assertions From: nikita.ppv@gmail.com (Nikita Popov) --089e01536de8893e8604e8f1ca06 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Oct 17, 2013 at 5:39 PM, J David wrote: > Assertions have three defining characteristics: > > 1) They are (potentially inefficient) checks run in > debug/non-production that completely disappear when run in production. > 2) When they pass, they produce no side effects. > 3) When an assertion fails, which can only ever happen in > debug/non-production, the program dies. > > Each component of this triad interacts with the others to make > assertions something different than the other tools in the debugging > toolbox, which is why they have value. > > Talking about catching exceptions thrown by an assertion failure seems > very contrary to that, because even if PHP is hardcoded to completely > ignore everything between "assert" and ";" when parsing in production, > any attempt to catch assertion-related exceptions won't get the same > treatment and will still be present in the production code. This can > cause a change in behavior, particularly in the case of catching all > exceptions, and encourages the generation of side effects (like trying > to recover an error) from an assertion test which will no longer be > performed when assertions are disabled for production. > Nobody is arguing that assertions should be used as a control-flow structure. It's still most useful to implement them as exceptions. Apart from being a lot better integrated than fatal errors (in particular they have such fancy things like stacktraces...) exceptions can also be gracefully handled where necessary. E.g. PHPUnit will catch the exception and tell you that an assertion failed, but it will still be able to continue running the rest of the testsuite. A framework (or front controller in general) can easily catch the exception at the top level and display an appropriate debugging page (rather than doing ugly register_shutdown_function hacks that are necessary to have even remotely graceful handling of fatals). A deamon or server will be able to process further requests, even if one particular had an assertion failure. Assertions shouldn't be used for control flow, but it should still be possible to handle them gracefully. Exceptions offer that, fatals do not. Nikita --089e01536de8893e8604e8f1ca06--