|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: raylee dot stu at gmail dot com
New email:
PHP Version: OS:


 [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 09:01:26 2023 UTC