|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75126 get_class returns the Class Name with namespace
Submitted: 2017-08-27 18:46 UTC Modified: 2017-08-27 19:18 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: raylee dot stu at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.1.8 OS: Window10.16253.rs3_release
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
35 - 21 = ?
Subscribe to this entry?

 [2017-08-27 18:46 UTC] raylee dot stu at gmail dot com
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:

namespace db\update\watcher;

class Foo {
  public function get_class_name(){
    echo get_class($this);
// outputs
// db\update\watcher\Foo;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-27 18:59 UTC] Wes dot example at example dot org
add a test script that actually works. get_class didn't change in decades
 [2017-08-27 19:18 UTC]
-Status: Open +Status: Not a bug
 [2017-08-27 19:18 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The behaviour of get_class() has always been to return the fully qualified class name, ever since namespacing was introduced in 5.3.0.

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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 14:01:28 2023 UTC