PHP Syntax OOP Components Properties Custom getters and setters

 

- Info:

- Since PHP doesn't support properties you can emulate behaviour by using private field and public getters and setters.

 

- Example:

- This example shows how to simulate getters and setters through private field and publich methods.

- Creat PHP Console Application Test.php.

 

Test.php

<?php

class Employee {

private $name;

public function getName() { return $this->name; }

public function setName($name) { $this->name = $name; }

}

?>