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

The Function Method

By Brent Roose

<?php

class x {
    function function() {
        echo __METHOD__;
    }
}

(new x)->function();
// x::function

?>

It is possible to name a method ‘function’. This is part of the relaxed keywords of PHP, which allows PHP keywords to be used as a method name.

Of course, it is also possible to create a function called method.

See Also

PHP Features

Last updated: 10 September 2026