Skip to content

Instantly share code, notes, and snippets.

@you-think-you-are-special
Last active December 19, 2015 16:18
Show Gist options
  • Save you-think-you-are-special/5982327 to your computer and use it in GitHub Desktop.
Save you-think-you-are-special/5982327 to your computer and use it in GitHub Desktop.
<?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