Self In An Interface

<?php

interface i {
    function foo(self $i);
}

class x implements i {
    //Declaration of x::foo(x $i) must be compatible with i::foo(i $i)
    function foo(self $i) {}

    // OK
    function foo(i $i) {}
}

The keyword self in an interface represents that same interface: it does not represent the host class. Hence, using self as return type means that the method must return an object that implements the type i, not of the host class.

See Also

PHP Features

Last updated: 14 July 2026