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: Closed Package: Unknown/Other Function
PHP Version: 7.3.27 OS: Ubuntu 20.04
Private report: No CVE-ID: None
 [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>
 [2021-04-19 17:54 UTC] git@php.net
Automatic comment on behalf of jhdxr (author) and web-flow (committer)
Revision: https://github.com/php/doc-en/commit/dd522120279a5d08a8aeeaabfaafdea235991d72
Log: fix #80766  namespaced assert is no longer allowed
 [2021-04-19 17:54 UTC] git@php.net
-Status: Verified +Status: Closed
 [2021-04-20 02:04 UTC] git@php.net
Automatic comment on behalf of mumumu
Revision: https://github.com/php/doc-ja/commit/b57a2f837a098a98d3f80850a14c2185251a9b77
Log: fix #80766 namespaced assert is no longer allowed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC