php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50200 get_class() is not the same as get_class($this)
Submitted: 2009-11-17 08:47 UTC Modified: 2009-11-17 10:04 UTC
From: sjoerd-php at linuxonly dot nl Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
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: sjoerd-php at linuxonly dot nl
New email:
PHP Version: OS:

 

 [2009-11-17 08:47 UTC] sjoerd-php at linuxonly dot nl
Description:
------------
The documentation on get_class() does not specify what happens when the parameter is omitted. I assumed the parameter defaults to $this, but this is not the case.

Note that this may also be a bug in the implementation instead of the documentation.

Reproduce code:
---------------
<?php
class A {
  function a() {
    echo get_class();
    echo get_class($this);
  }
}

class B extends A { }
$b = new B();
$b->a();
?>

Actual result:
--------------
get_class() in A will return A, where get_class($this) will return B.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-17 09:14 UTC] rquadling@php.net
Example #2 Using get_class() in superclass clearly covers this.

 [2009-11-17 10:00 UTC] sjoerd-php at linuxonly dot nl
I thought the examples were informative instead of normative.
 [2009-11-17 10:04 UTC] rquadling@php.net
The examples are part of the documentation. As they say, a picture 
paints a thousand words.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 08:00:01 2026 UTC