Skip to content

Instantly share code, notes, and snippets.

@honbin
Created December 13, 2012 06:13
Show Gist options
  • Save honbin/4274473 to your computer and use it in GitHub Desktop.
Save honbin/4274473 to your computer and use it in GitHub Desktop.
<?php
trait Accessors
{
public function __get($property)
{
if(property_exists($this, $property)) {
return $this->$property;
}
}
public function __set($property, $value)
{
if(property_exists($this, $property)) {
$this->$property = $value;
}
return $this;
}
}
}
class Hoge
{
use Accessors;
private $hoge;
}
$obj = new Hoge();
$obj->hoge = "hoge";
echo $obj->hoge; #=>hoge
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment