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

Invoke

It is possible to invoke an object, that means calling a function built with the object as the function name.

Invocation is based on the __invoke magic method.

Being invokable, or invocable, means that an object may be used as a function name.

<?php

class elephpant {
    function __invoke($a) {
        echo 'I am '.$a;
    }
}

$elephpant = new elephpant;
$elephpant('elephpant'); // I am elephpant

?>

Documentation

See Also