Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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: 09 November 2026