Req #69269 [Opn->Csd]: Allow assert to execute a closure
| From: | nikic@php.net | Date: | Fri, 20 Mar 2015 12:59:04 +0000 |
| Subject: | Req #69269 [Opn->Csd]: Allow assert to execute a closure | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191482@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69269&edit=1
ID: 69269
Updated by: nikic@php.net
Reported by: tom at r dot je
Summary: Allow assert to execute a closure
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: *General Issues
Operating System: any
PHP Version: 5.6.6
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
PHP 7 will provide an ini option to disable assert without any runtime cost, see https://wiki.php.net/rfc/expectations. Which is
what you want, only without having to use a closure.
Previous Comments:
------------------------------------------------------------------------
[2015-03-20 12:18:13] tom at r dot je
Description:
------------
Currently the manual helpfully states on http://php.net/manual/en/function.assert.php
that " The advantages of a string assertion are less overhead when assertion checking is
off"
Which makes perfect sense. The disadvantages, of course, are that readability is reduced and IDE
hints/highlighting won't work and the parser won't immediately catch parse errors in the
string.
As a happy medium I propose it would be better if assert() could take a closure as it's first
argument:
assert(function() {
return 2 < 1;
});
This has the best of both worlds as the code wouldn't be executed unless assertions are turned
on.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69269&edit=1