php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80766 assert() can be imported via use statement
Submitted: 2021-02-18 00:24 UTC Modified: 2021-02-22 09:30 UTC
From: smokey101stair at gmail dot com Assigned:
Status: Verified Package: Unknown/Other Function
PHP Version: 7.3.27 OS: Ubuntu 20.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smokey101stair at gmail dot com
New email:
PHP Version: OS:

 

 [2021-02-18 00:24 UTC] smokey101stair at gmail dot com
Description:
------------
In PHP 7, `assert` became a language construct and cannot be redefined as a user function. Typically language constructs can't be imported via use statements, however, it seems that `assert` can be imported via a use statement. I'm not sure if this is intentional or not for BC purposes. PHP throws a ParseError when trying to import other language constructs, such as `isset`, so I would expect importing `assert` to throw as well.

Test script:
---------------
// Works, unexpectedly
namespace Foo {
    use function assert;
}

// Doesn't work, as expected
namespace Foo {
    use function isset;
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-18 10:49 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2021-02-18 10:49 UTC] cmb@php.net
While `isset` is a keyword, `assert` is not.  This is by design,
and allows to define a namespace assert() function[1].  This is
apparently not yet documented in the manual.

[1] <https://wiki.php.net/rfc/expectations#namespaced_assert>
 [2021-02-22 09:18 UTC] nikic@php.net
Defining a namespaced assert is not allowed: https://3v4l.org/bRAbN

Nothing wrong with an explicit import though. assert() is still considered a normal function, albeit one that is specially handled to respect zend.assertions.
 [2021-02-22 09:30 UTC] cmb@php.net
> Defining a namespaced assert is not allowed

Ah, right!   However, it was allowed[1].  All that should be
documented.

[1] <https://3v4l.org/7CUEL>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 19 17:01:23 2021 UTC