Last active
December 19, 2015 16:18
-
-
Save you-think-you-are-special/5982327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait GetterSetter | |
{ | |
public function __get($name) | |
{ | |
$getter = 'get' . ucfirst($name); | |
if ( ! method_exists($this, $getter) ) | |
{ | |
throw new \Exception('Not found getter for property - ' . $name); | |
} | |
return $this->$getter(); | |
} | |
public function __set($name, $value) | |
{ | |
$setter = 'set' . ucfirst($name); | |
if ( ! method_exists($this, $setter) ) | |
{ | |
throw new \Exception('Not found setter for property - ' . $name); | |
} | |
$this->$setter($value); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment