⊗ppOpBsCn 8 of 107 menu

Constructor in OOP in PHP

There is a special method that will be called at the moment of creating a new object of the class. This method is called __construct. Let's make it in our class:

<?php class User { public function __construct() { echo '+++'; } } ?>

Let's now create an object of the class and make sure that the method is called:

<?php new User(); // will output '+++' ?>

Make a constructor for the Employee class.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline