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
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:
MUST BE VALID
Solve the problem:
50 + 15 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC