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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Dec 21 15:01:29 2024 UTC