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

From: Date: Fri, 27 Oct 2017 09:57:12 +0000
Subject: Bug #75445 [Opn->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-212336@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: Open +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: By design, for the reason you already mentioned. It's also defined in the RFC, see https://wiki.php.net/rfc/expectations#namespaced_assert. Previous Comments: ------------------------------------------------------------------------ [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 (#212336) next »