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;
}
}
?>
See Also
- PHP Getters and Setters Tutorial: Encapsulation Guide
- The Magic of PHP Getters, Setters, and Readonly Classes: Crafting Clean and Efficient Code