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

new

new creates a new object from a class. This operation is called the instantiation.

The class must be available at instantiation call: the engine searches for it in the declared classes, then calls the autoloader to find it. In case no class is found, an error is emitted.

The instantiation immediately calls the constructor of the object: it is the method called __construct.

The constructor defines how many arguments are needed. When no argument is needed, new may also be called without parentheses.

<?php

    class Elephpant {
        function __construct($a = 1) {}
    }

    // instantiation
    $trunk = new elephpant($a);

    $herd = new y;

?>

Documentation

See Also