Created
December 13, 2012 06:13
-
-
Save honbin/4274473 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 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