Created
October 22, 2012 02:44
-
-
Save ngyuki/3929351 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Hoge | |
{ | |
protected $_val; | |
public function __construct($val) | |
{ | |
$this->_val = $val; | |
} | |
public function say() | |
{ | |
echo "say $this->_val\n"; | |
} | |
} | |
class HogeSub extends Hoge | |
{ | |
public static function setVal(Hoge $hoge, $val) | |
{ | |
$hoge->_val = $val; | |
} | |
} | |
class HogeProtect extends Hoge | |
{ | |
private $_obj; | |
public function __construct($obj) | |
{ | |
$this->_obj = $obj; | |
} | |
public function __get($name) | |
{ | |
return $this->_obj->$name; | |
} | |
public function __set($name, $val) | |
{ | |
$this->_obj->$name = $val; | |
} | |
} | |
/// | |
$hoge = new Hoge(1); | |
// say 1 | |
$hoge->say(); | |
HogeSub::setVal($hoge, 2); | |
// say 2 | |
$hoge->say(); | |
$hogeProtect = new HogeProtect($hoge); | |
$hogeProtect->_val = 3; | |
// say 3 | |
$hoge->say(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment