|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74784 get_class(NULL) return current class
Submitted: 2017-06-19 20:38 UTC Modified: 2017-06-19 20:44 UTC
From: jonathanschweder at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.0.20 OS: Ubuntu 16.04.2 LTS
Private report: No CVE-ID: None
 [2017-06-19 20:38 UTC] jonathanschweder at gmail dot com
This is more a doubt that a bug, when I don't pass any param to the function get_class() or pass a variable that it value is NULL the function return the current Class where the script run's, is this behavior correct ?

I ask because some time when I try to debug something and use the function get_class() I will pass some var and sometimes this var is NULL, turning my debug a bit confuse because any other scalar value that I pass this will throw an exception saying that the param is not an object.

Sorry for any noob question and thanks for any feedback.

Test script:

class Foo
    public function bar()
        echo get_class();

$foo = new Foo;
$foo->bar();// Foo

Expected result:
Throw exception saying that the param is not a object instance.

Actual result:
Return the name of the current class


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-19 20:44 UTC]
-Status: Open +Status: Not a bug
 [2017-06-19 20:44 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
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 10:01:24 2023 UTC