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

Relaxed Syntax

Relaxed syntax refers to the extra freedom in naming class elements, such as constant and methods, compared to creating global constant and functions.

In particular, keywords are allowed for class constants and methods, while they are forbidden for global constants and functions.

Note that using PHP keywords for method names may bring confusion to the next code reader.

<?php

// That is not possible, as array is already reserved
// function array() {}
// const array = [];

class Elephpant {
      function array() { return [1]; }
    const array = [2];

    function trumpet() {
        // This is not a syntax that is expected
        return $this->array() + self::array;
    }
}

?>

Documentation

See Also