Req #70582 [Opn]: Referncing NotExistingClass::class should trigger error/warning/notice
| From: | andreas dot stangl at stansotec dot de | Date: | Fri, 25 Sep 2015 14:24:19 +0000 |
| Subject: | Req #70582 [Opn]: Referncing NotExistingClass::class should trigger error/warning/notice | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196243@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70582&edit=1
ID: 70582
User updated by: andreas dot stangl at stansotec dot de
Reported by: andreas dot stangl at stansotec dot de
Summary: Referncing NotExistingClass::class should trigger
error/warning/notice
Status: Open
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Class/Object related
Operating System: Any
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
Changed "Package" to "Class/Object related".
Previous Comments:
------------------------------------------------------------------------
[2015-09-25 14:18:07] andreas dot stangl at stansotec dot de
Description:
------------
When referencing the "magic" class constant "::class" the interpreter does not
care if the given class does not exist.
If I have e.g. a class "My\FancyClass" and I access the "class" constant like
echo My\FancyClass::class;
I get
"My\FancyClass"
(which is pretty cool especially for unit tests). But if e.g. My\FancyClass gets renamed to
"My\FoobarClass" the interpreter will not complain at all.
But referencing any other (not existing) constant of a not existing class like
echo My\FoobarClass::blah;
Produces a fatal error. This looks a little inconsistent to me.
Test script:
---------------
<?php
namespace My;
class FancyClass {}
echo FancyClass::class . "\n"; // useful
echo NotExistingClass::class . "\n"; // imho not so useful :-/
echo NotExistingClass::blah; // fatal error
Expected result:
----------------
My\FancyClass
PHP Fatal error: Class 'My\NotExistingClass' not found in testScript.php on line 7
Actual result:
--------------
My\FancyClass
My\NotExistingClass
PHP Fatal error: Class 'My\NotExistingClass' not found in testScript.php on line 8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70582&edit=1