Bug #75912 [Nab]: No name resolution on D::class (even with warnings enabled)
| From: | cmb@php.net | Date: | Sun, 04 Feb 2018 17:59:42 +0000 |
| Subject: | Bug #75912 [Nab]: No name resolution on D::class (even with warnings enabled) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213807@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75912&edit=1
ID: 75912
Updated by: cmb@php.net
Reported by: ejrx7753 at gmail dot com
Summary: No name resolution on D::class (even with warnings
enabled)
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Mac OS, Ubuntu
PHP Version: 7.1.14
Block user comment: N
Private report: N
New Comment:
FTR: this isssue is clearly documented[1]:
| The class name resolution using ::class is a compile time
| transformation. That means at the time the class name string is
| created no autoloading has happened yet. As a consequence, class
| names are expanded even if the class does not exist. No error is
| issued in that case.
[1] <http://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class>
Previous Comments:
------------------------------------------------------------------------
[2018-02-03 22:16:59] kelunik@php.net
It resolves the name according to name resolution rules, so I think that wording is fine.
------------------------------------------------------------------------
[2018-02-03 21:54:48] ejrx7753 at gmail dot com
I see... sounds like a documentation issue then, as ""allows for fully qualified class
name resolution" seems to imply other things.
------------------------------------------------------------------------
[2018-02-03 21:46:48] levim@php.net
It expands to what the fully qualified class name *would be*. It will not trigger an autoload.
Consider instead this snippet:
<?php
namespace Foo {
var_dump(C::class);
var_dump(\D::class);
}
?>
Which prints:
string(5) "Foo\C"
string(1) "D"
------------------------------------------------------------------------
[2018-02-03 21:38:33] ejrx7753 at gmail dot com
Description:
------------
I'm able to enter any random string of characters and add "::class" and it will work
fine without error. PHP Documentation clearly states that this ::class feature "allows for
fully qualified class name resolution". It should be a fatal error just as with new C().
Quote: "The special ::class constant are available as of PHP 5.5.0, and allows for fully
qualified class name resolution at compile, this is useful for namespaced classes:"
(http://php.net/manual/en/language.oop5.constants.php)
Test script:
---------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
var_dump(C::class);
var_dump(\D::class);
Expected result:
----------------
Expected a fatal error
Actual result:
--------------
string(1) "C"
string(1) "D"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75912&edit=1