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 PHP 8 – Functions and Methods.

Related : Class, __call() Method, Default Parameter, Fossilized Methods, Functions, Properties, Return, Static Method, Visibility, Call Graph, Callbacks, Impure Function, Method Compatibility, Pure Function, Trait, Method Collision, Non-static, Relay Function