Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69599 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5992 invoked from network); 17 Oct 2013 10:51:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 10:51:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.181 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.220.181 mail-vc0-f181.google.com Received: from [209.85.220.181] ([209.85.220.181:61281] helo=mail-vc0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/62-22512-341CF525 for ; Thu, 17 Oct 2013 06:51:47 -0400 Received: by mail-vc0-f181.google.com with SMTP id id10so1091220vcb.12 for ; Thu, 17 Oct 2013 03:51:43 -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:from:date:message-id :subject:to:cc:content-type; bh=GSCoBvwqbYyGuwVgWdpdQYr4Nx+0eEZ6a7FQfUt3+38=; b=C1vqRGK4Kg7I95kEEgUzNrJw5OoOcxYXhdX/CksnvJDmjxe9vG7CjoEPIU2stQ1N/F idMwh3enwoI5wS3O+L8rJkQ3IKLAVMEtbGvSCFLbD5Tgla62FBjcbGJAv4+k0H1CFSwF bPFX1E1zwKi66uC5Zm69eDNY/GH+TLuEXQBcz8+eIgnzTUA/q+XXdR6kCR6lqyJEU+Dd WCMpk0CHuPcjfAn9+BciwiOrBOoMHFWDHJR2VRIW2oKtnYw0j4mWVe5xWo4dcevcgqDb wJwg3cm4pNeLGHrlXwQZFC0ycslld145sPE8+AwEDlocWOLPzPuniJ5ZAvRRSEuxi/4q BV1g== X-Received: by 10.220.10.194 with SMTP id q2mr6296590vcq.2.1382007103655; Thu, 17 Oct 2013 03:51:43 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.73.197 with HTTP; Thu, 17 Oct 2013 03:51:03 -0700 (PDT) In-Reply-To: References: Date: Thu, 17 Oct 2013 12:51:03 +0200 X-Google-Sender-Auth: ODQhLuvkhGffiLGlXfLGhIEQhdE Message-ID: To: Joe Watkins Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c3b9447dc68f04e8ed9a47 Subject: Re: [PHP-DEV] Assertions From: jpauli@php.net (Julien Pauli) --001a11c3b9447dc68f04e8ed9a47 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Oct 17, 2013 at 9:25 AM, Joe Watkins wrote: > Morning All, > > I'd like to draw some attention to how poor assertions are in PHP. > > The current assertion API is not usable in my opinion; it has a > considerable overhead, relies on eval(), and is generally poorly > implemented. > > I have done some work toward implementing assert at the Zend > level, giving assertions a more modern, usable feel to them. > > https://github.com/krakjoe/**php-src/compare/assert > > This implementation of assert removes the old implementation and > associated functions and INI settings, and replaces it with a single INI > setting to control assertion compilation. > > Failed assertions throw an AssertionException (which extends > ErrorException with a severity of E_ERROR), setting the message of the > exception to the expression asserted. > > The syntax of assertion is the same as [all] other languages: > > T_ASSERT expr ';' > > This means that assert("some code here") will pass assertion > causing no error, because strings are no longer treated as code, because > eval is evil(); > > Setting zend.assertions=0 system configuration setting will stop > ZEND_ASSRT compilation. > > So, we have: > > try { > assert (PHP != JUNK); > > > } catch(AssertionException $ex) { > printf("Assertion failed: %s\n", $ex->getMessage()); > printf("Something is horribly wrong ...\n"); > } > > Better, no ?? I like the idea. However, there is always the debatte about if a Core feature should throw an Exception or generate an error. In our current system, they don't throw Exceptions but generate errors. Also : someone could use a callback, and then make them throw exceptions if he wants to ; the callback on assertion fail, which IMO is a good feature, has dissapeared in your patch. Julien.Pauli --001a11c3b9447dc68f04e8ed9a47--