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

Method

Methods are functions, dedicated to a class. They are defined inside the body of a class, and may only be accessed in relation to that class: via an object, the class name or another method.

Methods are defined in traits, and then imported in a class for usage.

Methods are also called member functions. Indeed, they are functions, but they belong to an object, just like a member, or property. This is less used.

<?php

    class X {
        public function foo() {
            echo "I am foo!\n";
        }
    }
    
    $x = new Y();
    $y->foo(); // calling the foo method, defined in x,

?>

Documentation

See Also