Bug #70241 [Asn]: Skipped assertions affect Generator returns
| From: | cmb@php.net | Date: | Tue, 11 Aug 2015 19:39:31 +0000 |
| Subject: | Bug #70241 [Asn]: Skipped assertions affect Generator returns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195141@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70241&edit=1
ID: 70241
Updated by: cmb@php.net
Reported by: me at kelunik dot com
Summary: Skipped assertions affect Generator returns
Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.0.0beta3
Assigned To: bwoebi
Block user comment: N
Private report: N
New Comment:
> It doesn't mean ignore all the side-effects caused by the
> content of assert(). It just means ignoring the code generated
> by it.
Turning off assertions would not make much sense, if only the
overhead of checking the value of the expression would be skipped.
What actually may be very costly is the evaluation the expression
itself (consider checking each element of a large array for some
condition).
AFAIK, "no" programming language does evaluate the expression, if
assertion checking is disabled. At least this is so with PHP 5,
cf. <http://3v4l.org/YLofr> and <http://3v4l.org/RRp6m>.
> Additional note: zend.assertions=0 and zend.assertions=-1
> *should* IMHO behave the same.
ACK. However, IMHO, the current behavior with zend.assertions=0 is
in error.
Previous Comments:
------------------------------------------------------------------------
[2015-08-11 18:20:09] bwoebi@php.net
Additional note: zend.assertions=0 and zend.assertions=-1 *should* IMHO behave the same. Which would
imply that it definitely should return a Generator in both cases.
------------------------------------------------------------------------
[2015-08-11 18:20:04] bwoebi@php.net
Additional note: zend.assertions=0 and zend.assertions=-1 *should* IMHO behave the same. Which would
imply that it definitely should return a Generator in both cases.
------------------------------------------------------------------------
[2015-08-11 18:16:19] bwoebi@php.net
Precisely, it means not producing any code. "-1 - don't generate any code (zero-cost,
production mode)" from the RFC.
It doesn't mean ignore all the side-effects caused by the content of assert(). It just means
ignoring the code generated by it.
So, the reporter is right. Either it's a mistake in the RFC or a bug.
------------------------------------------------------------------------
[2015-08-11 18:07:58] cmb@php.net
zend.assertions=-1 means don't produce any code, so the script
behaves as if there was no assert statement.
------------------------------------------------------------------------
[2015-08-11 17:58:28] me at kelunik dot com
Description:
------------
Assertion configuration can change code behavior:
php -d zend.assertions=1 test.php -> Generator
php -d zend.assertions=-1 test.php -> bool(true)
Test script:
---------------
<?php
function foo() {
assert(yield 42);
return true;
}
var_dump(foo());
Expected result:
----------------
php -d zend.assertions=1 test.php -> Generator
php -d zend.assertions=-1 test.php -> Generator
Actual result:
--------------
php -d zend.assertions=1 test.php -> Generator
php -d zend.assertions=-1 test.php -> bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70241&edit=1