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

From: Date: Wed, 20 Dec 2017 13:17:30 +0000
Subject: Bug #75445 [Com]: 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-213175@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
 Comment by:         mikko dot rantalainen at peda dot 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#213175) next »