$this $this

<?php

class x {
    private $p = 'Yes!';

    function foo() {
        // valid code
        echo $this->$this;
    }

    function __toString() {
        return 'p';
    }
}

(new x)->foo();

$this is the pseudo-variable that represents the current object. It is also a variable, like others, and may be used to describe a dynamic property.

Since a property must be described as a string, it is possible to use the magic method __toString() to convert the object into a string, and map an existing property.

See Also

PHP Features

Last updated: 14 July 2026