Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69643 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3614 invoked from network); 17 Oct 2013 17:33:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 17:33:38 -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.214.173 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:58748] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/F2-12663-17F10625 for ; Thu, 17 Oct 2013 13:33:37 -0400 Received: by mail-ob0-f173.google.com with SMTP id vb8so2205572obc.32 for ; Thu, 17 Oct 2013 10:33:34 -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=NqYjl17nW/jRozr1vUDIL/WjWUwN+MH6zluPYD7HgPY=; b=zYXZTtzy0C4lkTltaEv6jd0gIOMGRlGd15mrK9LDx8Pbu/TZXGhsA0aM/wTrs6CN67 jjxy89o5NwTDhwWNRkHC0f0cvxFlCebr4PrQcUHrh8fp/m3JMDjHsEs3wNktplNk5Rt2 YULjrbusfEpORm6AqVAei/36sJgq9Du0YTRqpkvos7XPg0CTt8piCoRtWG1dZWwtZS03 50y2E8N1ILWagkUrojHejLXk5pN5aH2SDPR2cv8XEi5ND6BHcNbnhE8smAPVSulegy7h tFBLyV4sqIa9egj3Ce2VZ6MyLKcU9lCaaZ2ap/0cKRsXypTLqFl12p73Y88w9hzXlIk7 82UA== MIME-Version: 1.0 X-Received: by 10.182.40.201 with SMTP id z9mr14210713obk.45.1382031214147; Thu, 17 Oct 2013 10:33:34 -0700 (PDT) Received: by 10.182.54.112 with HTTP; Thu, 17 Oct 2013 10:33:34 -0700 (PDT) In-Reply-To: References: <525FC834.4060501@php.net> <1534105.bNC2os93J1@rofl> <525FDAC3.6060103@php.net> Date: Thu, 17 Oct 2013 19:33:34 +0200 Message-ID: To: J David Cc: Joe Watkins , PHP internals , Michael Wallner Content-Type: multipart/alternative; boundary=001a11c33b02967f5204e8f33739 Subject: Re: [PHP-DEV] Assertions From: nikita.ppv@gmail.com (Nikita Popov) --001a11c33b02967f5204e8f33739 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Oct 17, 2013 at 7:03 PM, J David wrote: > All three cause unexpected behavior if the asserted condition is not > true and assertions are disabled because the condition was not > evaluated. > > In all three of those examples, the behavior you want is easily > obtained by throwing an exception. > > In fact, what some people might do in those situations is: > > assert($myObject->internalState == OBJECT_STATE_VALID, "internal > object state not valid"); > if ($myObject->internalState != OBJECT_STATE_VALID) > throw FMLException("internal object state not valid"); > > (In this case, you would probably do the PHPUnit stuff with assertions > disabled.) > > Assertions are a debugging/development check designed to facilitate > proof of correctness. They are not present or used in production > code. There is no danger that a failed assertion will ever cause a > production app to abort. They serve one purpose, which is to bring > things to a screeching halt when somethat that should never, ever > happen has happened. And their value comes *because* they are > independent of methods used to handle potentially-recoverable errors. > Sorry, I still don't understand what you're trying to say. Ignoring my last example, both PHPUnit and a "debug page" from the framework are clearly for debugging/development. Both examples just take the failed assertion and present it in a more appropriate form. I am most certain that you do *NOT* want to abort the whole unit test run because of an assertion failure in one single test. Tests are supposed to continue running even if individual ones fail. There is nothing inherently different between a test that failed because of an assertion and a test that failed because it threw an unexpected exception or returned a wrong value. In either case you want to see a test failure and continue to run. Just imagine how terrible it would be if the PHP test suite would stop running on the first test failure (of 12000 tests). Similarly, showing a friendly debugging page when an assertion fails does not seem to go against your idea of assertions. It just changes the presentation form to simplify debugging the cause by specifying additional information that is known to the framework (but not to the assertion itself). > Why do we need a new way to throw an exception? > > Why do we need to mess up another tool that has a different purpose to do > it? > > What's wrong with writing the three-line function one time to get the > behavior you want? > Those questions have a very simple answer: You can't disable code throwing exceptions ;) Assertions can be disabled. Nikita --001a11c33b02967f5204e8f33739--