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

Class Getter Method

Getters are methods used to access the values of a property. Getters may include formatting, or not.

Getters are usually created with a setter method.

Getters are built on top of private properties: that way, the getter is the main way to reach the data.

Getters may be replaced by a property hook.

Getters generate a lot of boilerplate code, as they must be created for each property, and are often reduced to returning the property itself. This does not help performance either, as a call to a property is now replaced by a method call.

<?php

    class Elephpant {
        private $property;
        
        public function getProperty() {
            return $this->property;
        }
    }

?>

Documentation

See Also