Doc #80766 [Ver->Csd]: assert() can be imported via use statement

From: Date: Mon, 19 Apr 2021 17:54:31 +0000
Subject: Doc #80766 [Ver->Csd]: assert() can be imported via use statement
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18713@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80766&edit=1 ID: 80766 Updated by: git@php.net Reported by: smokey101stair at gmail dot com Summary: assert() can be imported via use statement -Status: Verified +Status: Closed Type: Documentation Problem Package: Unknown/Other Function Operating System: Ubuntu 20.04 PHP Version: 7.3.27 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2021-02-22 09:30:02] 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-02-22 09:18:07] 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-18 10:49:24] 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-18 00:24:45] 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; } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80766&edit=1

« previous php.doc.bugs (#18713) next »