PHP

Constructors & property promotion (PHP)

Në shqip: Konstruktorët në PHP

ShpjegimiSQ

Konstruktori në PHP quhet __construct() dhe ekzekutohet kur krijon objektin. Që nga PHP 8, „property promotion“ të lejon t'i deklarosh dhe caktosh fushat direkt te parametrat e konstruktorit — shumë më pak kod.

EnglishEN

PHP's constructor is called __construct() and runs when you create the object. Since PHP 8, “property promotion” lets you declare and set properties right in the constructor's parameters — much less code.

Si ta mendosh

Si formulari i regjistrimit ditën e parë të shkollës.

Lexoje në anglisht

Like the registration form on the first day of school.

Shembull kodiphp

class Nxenes {
  public function __construct(
    private string $emri, private int $klasa = 10,
  ) {}
}

Terma të lidhur