php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75912 No name resolution on D::class (even with warnings enabled)
Submitted: 2018-02-03 21:38 UTC Modified: 2018-02-04 17:59 UTC
From: ejrx7753 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.14 OS: Mac OS, Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ejrx7753 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-02-03 21:38 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-03 21:46 UTC] levim@php.net
-Status: Open +Status: Not a bug
 [2018-02-03 21:46 UTC] 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:54 UTC] 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 22:16 UTC] kelunik@php.net
It resolves the name according to name resolution rules, so I think that wording is fine.
 [2018-02-04 17:59 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 08:01:34 2025 UTC