Bug #75126 [Opn->Nab]: get_class returns the Class Name with namespace
| From: | daverandom@php.net | Date: | Sun, 27 Aug 2017 19:18:14 +0000 |
| Subject: | Bug #75126 [Opn->Nab]: get_class returns the Class Name with namespace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210840@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75126&edit=1
ID: 75126
Updated by: daverandom@php.net
Reported by: raylee dot stu at gmail dot com
Summary: get_class returns the Class Name with namespace
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Window10.16253.rs3_release
PHP Version: 7.1.8
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The behaviour of get_class() has always been to return the fully qualified class name, ever since
namespacing was introduced in 5.3.0.
https://3v4l.org/HcYuG
To get the name of the class without the namespace, either functions such as strpos(), substr(),
strrchr(), basename() with appropriate path separator normalization, or reflection.
Previous Comments:
------------------------------------------------------------------------
[2017-08-27 18:59:32] Wes dot example at example dot org
add a test script that actually works. get_class didn't change in decades
------------------------------------------------------------------------
[2017-08-27 18:46:34] raylee dot stu at gmail dot com
Description:
------------
get_class in the versions before 7.1.8 returns only the class name, but now prefixed with namespace.
A option should be added in get_class([[object $object],[bool $include_namespace]])
Test script:
---------------
<?php
namespace db\update\watcher;
class Foo {
public function get_class_name(){
echo get_class($this);
}
}
// outputs
// db\update\watcher\Foo;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75126&edit=1