Encapsulation and visibility

Encapsulation protects the internal state of an object. Visibility controls access: public everywhere, protected in the class and its children, private in the class only. You expose methods rather than properties to keep control over the values.

Example

class Compte {
  private float $solde = 0;
  public function deposer(float $m): void { $this->solde += $m; }
}

Related concepts

The whole glossary