PHP Syntax OOP Classes Methods Predefined _set

 

- Info:

- _set() method takes as input a property name and a corresponding value.

- Returns TRUE if the method is successfully executed, and FALSE otherwise.

- You can overload this method with custom implementation.

 

- 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 {

var $name;

function __set($propName, $propValue) {

echo "Nonexistent variable: \$$propName!";

}

}

$employee = new Employee ();

$employee->name = "Mario";

$employee->title = "Executive Chef";

?>