Bug #55696 [NEW]: __CLASS__ includes the namespace definition
| From: | dohpaz dot php at dohpaz dot com | Date: | Wed, 14 Sep 2011 20:48:28 +0000 |
| Subject: | Bug #55696 [NEW]: __CLASS__ includes the namespace definition | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-163548@lists.php.net to get a copy of this message | ||
From:
Operating system:
PHP version: 5.3.8
Package: Unknown/Other Function
Bug Type: Bug
Bug description:__CLASS__ includes the namespace definition
Description:
------------
With the introduction of namespaces, the __CLASS__ magic constant has
changed (without being documented) to include the current namespace as part
of the class name. I submit that since there is a __NAMESPACE__ magic
constant that the __CLASS__ constant should be reverted to its previous
behavior. It seems more natural to concatenate __NAMESPACE__ and __CLASS__
to get a qualified name, rather than using basename() to get just the class
name.
At the very least, the documentation for namespaces
(http://php.net/namespace), Magic Constants
(http://us.php.net/manual/en/language.constants.predefined.php), and
Backwards Incompatible Changes
(http://us.php.net/manual/en/migration53.incompatible.php) should be
updated to reflect this change.
Test script:
---------------
<?php
namespace Foo;
class Bar {
public function __construct() {
echo __CLASS__ . PHP_EOL;
}
}
$bar = new Bar; // echo's Foo\Bar
?>
Expected result:
----------------
I expect the above test script to return just the class name (i.e., Bar).
Actual result:
--------------
The test script above returns the qualified class name (i.e., Foo\Bar).
--
Edit bug report at https://bugs.php.net/bug.php?id=55696&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55696&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55696&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55696&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=55696&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55696&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=55696&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=55696&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=55696&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=55696&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=55696&r=support
Expected behavior: https://bugs.php.net/fix.php?id=55696&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=55696&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=55696&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=55696&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55696&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55696&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=55696&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=55696&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=55696&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=55696&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=55696&r=mysqlcfg