Bug #75445 [Nab]: User-defined assert function is optimized away with zend.assertions=-1

From: Date: Wed, 20 Dec 2017 14:10:42 +0000
Subject: Bug #75445 [Nab]: User-defined assert function is optimized away with zend.assertions=-1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213179@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75445&edit=1 ID: 75445 Updated by: nikic@php.net Reported by: kelunik@php.net Summary: User-defined assert function is optimized away with zend.assertions=-1 Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 7.2.0RC5 Block user comment: N Private report: N New Comment: IIRC when we discussed this with @kelunik last time, throwing a fatal error if you try to define an assert() function seemed like the best way to resolve this. assert() is essentially a language-construct now, we should treat it as such. Previous Comments: ------------------------------------------------------------------------ [2017-12-20 13:17:27] mikko dot rantalainen at peda dot net The fact that namespaces are honored for assert() BUT the same optimization still happens (the call to assert() is blindly removed) should be explained on page http://php.net/manual/en/function.assert.php You cannot expect developers to read old RFC documents to find this out. ------------------------------------------------------------------------ [2017-10-27 09:57:08] nikic@php.net By design, for the reason you already mentioned. It's also defined in the RFC, see https://wiki.php.net/rfc/expectations#namespaced_assert. ------------------------------------------------------------------------ [2017-10-27 08:48:37] kelunik@php.net Description: ------------ Execute the test script: - php -d zend.assertions=1 test.php - php -d zend.assertions=0 test.php - php -d zend.assertions=-1 test.php assert() doesn't respect the namespace fallback, but assumes unqualified calls are equivalent to \assert() and optimize it away / jump around it with assertions disabled. This is unfortunate, as few people use \assert() over assert() and wouldn't gain zero-cost assertions without this behavior. Test script: --------------- <?php namespace Test { function assert() { global $foo; $foo = true; } } namespace Test { assert(); var_dump(isset($foo)); } Expected result: ---------------- bool(true) Actual result: -------------- bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75445&edit=1

« previous php.bugs (#213179) next »