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.