PHP Classes
A PHP class declares properties and methods. private means only code inside the class can touch the property, and $this refers to the current object. Inside methods, members are reached with the -> operator.
PHP
<?php
class Counter {
private int $value = 0;
public function increment(): void {
$this->value++;
}
public function value(): int {
return $this->value;
}
}
$counter = new Counter();
$counter->increment();
$counter->increment();
echo $counter->value(), "\n";