Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69635 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88171 invoked from network); 17 Oct 2013 15:39:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 15:39:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=jdavidlists@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jdavidlists@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: jdavidlists@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-ie0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:49877] helo=mail-ie0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/00-12663-FA400625 for ; Thu, 17 Oct 2013 11:39:27 -0400 Received: by mail-ie0-f174.google.com with SMTP id qd12so4183702ieb.5 for ; Thu, 17 Oct 2013 08:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=YO6L6WHmzxWNL/RVAU8P6cqaOWnE1HRA44+1pl4a04U=; b=RDzba+qPIVutjf9eUGZr2dAHAeEwe+7CqYBAfQnv+SRQ5WoR667YvRVbT03cwWZpSE fP4n9+MLK18GpzfTovQxMo3kiIah3KxsK5JzkpsACAcELE9HNSDKldwRHWYCJTmeAJX+ c4p0lGl753WaEBHcO/w6Gy0M79KS/vo5/5diAEY6fChJV/PzXKtcQUgxXs/S4WbXvFLR ZzVGzXo2Moi9vLljojwvqDCUpOAa9iKCgzgRHZshSC6wdoYLp67x+ROGXCvG4CU2asoi SPuMCbxElEipDD8njVXiXSsz+SSzCbBH9LtqwKoyqwVn5vc8gLGZVboxr5kMx2AQVWD1 WJWQ== MIME-Version: 1.0 X-Received: by 10.50.117.40 with SMTP id kb8mr26375689igb.60.1382024364562; Thu, 17 Oct 2013 08:39:24 -0700 (PDT) Sender: jdavidlists@gmail.com Received: by 10.43.180.131 with HTTP; Thu, 17 Oct 2013 08:39:24 -0700 (PDT) In-Reply-To: <525FDAC3.6060103@php.net> References: <525FC834.4060501@php.net> <1534105.bNC2os93J1@rofl> <525FDAC3.6060103@php.net> Date: Thu, 17 Oct 2013 11:39:24 -0400 X-Google-Sender-Auth: pulg7G3DT2s2IXQs6Bu3awRQt-I Message-ID: To: Joe Watkins Cc: PHP internals , Michael Wallner Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Assertions From: j.david.lists@gmail.com (J David) 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. If you want a concise easy-to-write test that throws an exception if it's not true and runs in production code in catchable way that doesn't abort the app, that is a great idea. But it is not an assertion. It is also already easy to do. Just write: function Expect($shouldBeTrue, $message) { if (!$shouldBeTrue) throw new FMLException($message); } Expect($myObject->internalState == OBJECT_STATE_VALID, "object state is not valid"); Customize as needed with your favorite exception type. Maybe there is some reason why a variant of this should be in the language core, although that's not immediately clear, but it seems really hard to justify redefining the solid and well-understood concept of assertions to do it. Thanks!