Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69600 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10294 invoked from network); 17 Oct 2013 10:55:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 10:55:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.50 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.50 mail-wg0-f50.google.com Received: from [74.125.82.50] ([74.125.82.50:54700] helo=mail-wg0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/73-22512-E12CF525 for ; Thu, 17 Oct 2013 06:55:26 -0400 Received: by mail-wg0-f50.google.com with SMTP id n12so2074640wgh.29 for ; Thu, 17 Oct 2013 03:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=pto7ojrijBmGBsiyOAgCK+U0lR2eWLQfeZJTaqS8Blc=; b=mbGYzFim34e1IuGdRTWii09eA64uZo9ChJGC8mrxqToHlNldvsB8r/ooUV3kk6UJMf gS13bdelxle6Fcu77iiN90LBZeAPQ1Wucz+zcLs6cqz+JCfYQD+d/KRBSn9T/sqe2Xt3 NbMHb9Vbh/VYziKTe7gDkypB2wqY3+D8oSZgDHIaRJgBQd/SJmypx5cpS5G0wOmWVr0d QCiMOBXIwxE2EbFUnWBX6goqu7E2xOgZ+bN0OxWA/nr4v/JwHn9WJYM75FmVJxeHKuHf zgG/Q2KaSmKlbvok4f7zFDMyzOz7uBvGrm6D29b6e3qUHid4yW9E79VB5AXjCU+gcOD1 UWcA== X-Received: by 10.180.198.5 with SMTP id iy5mr18963251wic.45.1382007323179; Thu, 17 Oct 2013 03:55:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.5.9 with HTTP; Thu, 17 Oct 2013 03:54:43 -0700 (PDT) In-Reply-To: References: Date: Thu, 17 Oct 2013 12:54:43 +0200 Message-ID: To: Julien Pauli Cc: Joe Watkins , PHP Internals Content-Type: multipart/alternative; boundary=047d7b624e2a9341a004e8eda787 Subject: Re: [PHP-DEV] Assertions From: krebs.seb@gmail.com (Sebastian Krebs) --047d7b624e2a9341a004e8eda787 Content-Type: text/plain; charset=ISO-8859-1 2013/10/17 Julien Pauli > 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< > 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. > Me too. And yes, I really use assertions. > 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. > Because assertions (or at least the resulting error) should be disabled in production I'd be fine with an error too. > 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 > -- github.com/KingCrunch --047d7b624e2a9341a004e8eda787--