PHP

Magic methods (__toString, __get)

Në shqip: Metodat magjike

ShpjegimiSQ

Metodat magjike fillojnë me dy nënvizime dhe PHP-ja i thërret vetë në raste të caktuara: __construct kur krijohet objekti, __toString kur e përdor si tekst, __get kur lexon një fushë që s'ekziston.

EnglishEN

Magic methods start with two underscores and PHP calls them itself in certain situations: __construct when the object is created, __toString when it's used as text, __get when you read a property that doesn't exist.

Si ta mendosh

Si prizat standarde: me spinën e duhur, çdo pajisje punon.

Lexoje në anglisht

Like standard sockets: with the right plug, any appliance works.

Shembull kodiphp

class Termi {
  public function __construct(private string $emri) {}
  public function __toString(): string { return "Termi: $this->emri"; }
}
echo new Termi("API");

Terma të lidhur