Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69620 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60073 invoked from network); 17 Oct 2013 13:50:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 13:50:02 -0000 Authentication-Results: pb1.pair.com header.from=marco@m-s-d.eu; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=marco@m-s-d.eu; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain m-s-d.eu from 209.85.223.170 cause and error) X-PHP-List-Original-Sender: marco@m-s-d.eu X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:37085] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/1A-12663-80BEF525 for ; Thu, 17 Oct 2013 09:50:01 -0400 Received: by mail-ie0-f170.google.com with SMTP id at1so4020572iec.15 for ; Thu, 17 Oct 2013 06:49:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=CfmMQFT1BqRcioy23CJwEUGFN+RW5f2TzVrqL6vQLFk=; b=DDwjIA7xrSuIkPhoxqjXfBVsX80A9ZDbsbhy8UptP+jn16WWm+wcOcUvvzeaG+VfGO Lo5bWG+/xevAe8NzYNMRZOOeMVAG/xQFdMLZr6oGTpsCJEPIBHcLGcPohgD1hBH0dpre SF0ZJwFogzFOivVwpjmJFhzeyEJsh2sxfbi9efbuH55UOz/i58buo5e+ZSDftMDYpbun ApnmKX8ObnRKRNgdklB2n8TPfthLq4kQMusUis/CH7JiFSjpmMCAW5MyfI3RdV79KvwW eitv93T5KOrHGvQzwWURR4hC0kSqAhoJXDszCe+RA/mcI8dtXInMKNBZ4m+rMhLnFd6K wzCw== X-Gm-Message-State: ALoCoQnxtLVkBRW/aMSgwDgoDTf6Z2/kWF/LhwH/MALdGCDDAbojDNM2KCEQcydZmv8F1u+pbUdk MIME-Version: 1.0 X-Received: by 10.50.13.104 with SMTP id g8mr26269037igc.30.1382017798065; Thu, 17 Oct 2013 06:49:58 -0700 (PDT) Received: by 10.64.240.8 with HTTP; Thu, 17 Oct 2013 06:49:57 -0700 (PDT) X-Originating-IP: [89.204.135.225] In-Reply-To: References: <525FC834.4060501@php.net> Date: Thu, 17 Oct 2013 15:49:57 +0200 Message-ID: To: Michael Wallner , internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Assertions From: marco@m-s-d.eu (Marco Schuster) (Stupid GMail, didn't reply automatically to the list) On Thu, Oct 17, 2013 at 3:41 PM, Michael Wallner wrote: > On 17 October 2013 15:34, Marco Schuster wrote: > >> I'd really like to do a simple try-assert-catch instead of writing e.g. >> if(isset($_GET["foo"]) { >> throw new InvalidArgumentException('$_GET[foo] not set'); >> } >> >> which would become >> assert(isset($_GET["foo"])); >> >> If you're doing a lot of isset-checks, then the assert-way is a bit of >> an abuse of assert, but it results in far less boilerplate crap. Maybe >> there's a way that e.g. one can write assertTerminate(cond) or >> assertException(cond) to differ between the behaviors. > > I'm not sure I can follow... > > function except($assertion, $description=null) { > if (!$assertion) > throw new Exception($description); > } > > except(isset($_GET["foo"])) This forces me to write a description and essentially duplicate the assertion code, while an AssertionException already contains a meaningful message ("Assertion in foo.php:1337 failed: isset($_GET["bar"])!=TRUE"). Marco