$this Is Not Of The Current Class

<?php

class a {
    function foo() {
        echo __CLASS__;          // a
        print get_class($this);  // a or b
    }
}

class b extends a {}

(new b)->foo();

$this is a pseudo-variable, that represents the current object of the calling object (dixit the manual): it is often portrayed as representing an object of the current class. This is commonly the case.

Yet, it is possible of this object to be an instance of another class. This happens with a child of the class, in particular when that child hasn’t defined a method that is present in the parent. The fallback mechanism will use the parent class.

In the end, this is still compatible.

See Also

PHP Features

Last updated: 14 July 2026