Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69597 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93254 invoked from network); 17 Oct 2013 07:25:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2013 07:25:32 -0000 X-Host-Fingerprint: 80.4.21.210 cpc22-asfd3-2-0-cust209.1-2.cable.virginmedia.com Received: from [80.4.21.210] ([80.4.21.210:25272] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/A0-22512-AE09F525 for ; Thu, 17 Oct 2013 03:25:30 -0400 Message-ID: To: internals@lists.php.net Date: Thu, 17 Oct 2013 08:25:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.4.21.210 Subject: Assertions From: krakjoe@php.net (Joe Watkins) 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 ?? Cheers Joe