/ Published in: PHP
OOP style getters and setters in PHP.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Person { private $first; private $last; public setName ($name) { } public getName ($name) { } public function __set ($name, $value) { $setter = 'set' . $key; $this->$setter($value); return $value; } trigger_error('Undefined property via ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); } public function __get ($name) { $getter = 'set' . $key; return $this->$getter(); } trigger_error('Undefined property via ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); } } ?>