php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77559 Support callable::class and array::class
Submitted: 2019-02-03 03:53 UTC Modified: 2019-02-03 04:39 UTC
From: mister dot pedantic at example dot org Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Irrelevant
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: mister dot pedantic at example dot org
New email:
PHP Version: OS:

 

 [2019-02-03 03:53 UTC] mister dot pedantic at example dot org
Description:
------------
AFAIK, all ::class work except these two.

Thanks.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-03 03:58 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-02-03 03:58 UTC] requinix@php.net
Neither of those are classes.
 [2019-02-03 04:04 UTC] requinix@php.net
Actually this should get a longer answer.

array and callable are keywords. They cannot be used for classes.
http://php.net/manual/en/reserved.keywords.php

int and string and such are not keywords, so int::class and string::class are supported. However at this time you cannot create classes named "int" or "string" because PHP is reserving those for its own possible future implementation.
 [2019-02-03 04:22 UTC] mister dot pedantic at example dot org
Also static is a keyword, but static::class works. they are all de-facto classes/types.
 [2019-02-03 04:39 UTC] requinix@php.net
https://3v4l.org/FohH3

static is a special case. It needs to be a keyword because it can be used for syntax (static class methods and properties and static variables) but it can also be used like self and parent (which aren't keywords). In fact you can see the deliberate support for "static" as a pseudo-class name having to be written right into the parser:
https://github.com/php/php-src/blob/PHP-7.3.1/Zend/zend_language_parser.y#L1038
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 10:01:29 2024 UTC