Bug #73875 [Com]: assert() evaluated despite runtime assert_options(ASSERT_ACTIVE, 0);
| From: | vedad at kajtaz dot net | Date: | Fri, 06 Jan 2017 14:32:36 +0000 |
| Subject: | Bug #73875 [Com]: assert() evaluated despite runtime assert_options(ASSERT_ACTIVE, 0); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206317@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73875&edit=1
ID: 73875
Comment by: vedad at kajtaz dot net
Reported by: vedad at kajtaz dot net
Summary: assert() evaluated despite runtime
assert_options(ASSERT_ACTIVE, 0);
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: FreeBSD 10.1
PHP Version: 7.0.14
Block user comment: N
Private report: N
New Comment:
Expressions are allowed in assertions since PHP 7.0:
> 7.0.0 assert() is now a language construct and not a function. assertion() can now be an
> expression.
That being said, it is either undocumented or plain wrong that the expression be evaluated despite
asserts being disabled.
Previous Comments:
------------------------------------------------------------------------
[2017-01-06 14:17:04] fernando at null-life dot com
> assert($assert = true);
Shouldn't this line be
> assert('$assert = true');
After changing it I get the expected result:
PHP VERSION 7.0.13 running
cli sapi.
Initial settings:
zend.assertions: 1
assert.active: 1
After altering settings:
zend.assertions: 1
assert.active: 0
Code in assert() was NOT evaluated
------------------------------------------------------------------------
[2017-01-06 13:28:54] vedad at kajtaz dot net
Actually, setting zend.assertions to 0 produces the same effect - expression in assert is still
evaluated.
echo 'PHP VERSION '.PHP_VERSION.' running '.PHP_SAPI.'
sapi.'.PHP_EOL;
echo 'Initial settings:'.PHP_EOL;
echo 'zend.assertions: '.ini_get('zend.assertions').PHP_EOL;
echo 'assert.active: '.ini_get('assert.active').PHP_EOL;
ini_set('zend.assertions', '0');
assert_options(ASSERT_ACTIVE, 0);
echo 'After altering settings:'.PHP_EOL;
echo 'zend.assertions: '.ini_get('zend.assertions').PHP_EOL;
echo 'assert.active: '.ini_get('assert.active').PHP_EOL;
$assert = false;
assert($assert = true);
if($assert)
echo 'Code in assert() was evaluated'.PHP_EOL;
else
echo 'Code in assert() was NOT evaluated'.PHP_EOL;
------------------------------------------------------------------------
[2017-01-05 18:31:11] vedad at kajtaz dot net
Description:
------------
Expressions in assert() are evaluated despite setting assert_options(ASSERT_ACTIVE, 0) at runtime.
I understand one should use zend.assertions in PHP 7+, yet IMHO this is either a documentation bug,
or a misbehavior.
Test script:
---------------
echo 'PHP VERSION '.PHP_VERSION.' running '.PHP_SAPI.'
sapi.'.PHP_EOL;
echo 'Initial settings:'.PHP_EOL;
echo 'zend.assertions: '.ini_get('zend.assertions').PHP_EOL;
echo 'assert.active: '.ini_get('assert.active').PHP_EOL;
assert_options(ASSERT_ACTIVE, 0);
echo 'After altering settings:'.PHP_EOL;
echo 'zend.assertions: '.ini_get('zend.assertions').PHP_EOL;
echo 'assert.active: '.ini_get('assert.active').PHP_EOL;
$assert = false;
assert($assert = true);
if($assert)
echo 'Code in assert() was evaluated'.PHP_EOL;
else
echo 'Code in assert() was NOT evaluated'.PHP_EOL;
Expected result:
----------------
PHP VERSION 7.0.14 running cli sapi.
Initial settings:
zend.assertions: 1
assert.active: 1
After altering settings:
zend.assertions: 1
assert.active: 0
Code in assert() was NOT evaluated
Actual result:
--------------
PHP VERSION 7.0.14 running cli sapi.
Initial settings:
zend.assertions: 1
assert.active: 1
After altering settings:
zend.assertions: 1
assert.active: 0
Code in assert() was evaluated
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73875&edit=1