php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jonathanschweder at gmail dot com
New email:
PHP Version: OS:

 

 [2017-06-19 20:38 UTC] jonathanschweder at gmail dot com
Description:
------------
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:
---------------
<?php

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-19 20:44 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2017-06-19 20:44 UTC] peehaa@php.net
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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jul 04 18:01:26 2020 UTC