Created
October 24, 2012 03:23
-
-
Save sanglt/3943490 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 | |
| // Class String | |
| class String { | |
| // protected variable | |
| protected $_string; | |
| // public variable | |
| public $string; | |
| // Assign string to public variable | |
| public function __construct($string) { | |
| $this->string = $string; | |
| } | |
| // Assign string to protected variable | |
| public function setValue($string) { | |
| $this->_string = $string; | |
| } | |
| /** | |
| * get CleanUp object | |
| * @return \CleanUp | |
| */ | |
| public function getCleanUp() { | |
| return new CleanUp($this); | |
| } | |
| } | |
| // Class CleanUp | |
| class CleanUp extends String { | |
| protected $_object; | |
| public function __construct($object) { | |
| $this->_object = $object; | |
| } | |
| public function doAction() { | |
| // Clean this object | |
| $vars = get_object_vars($this->_object); | |
| return $vars; | |
| } | |
| } | |
| $stringObj = new String('Andy 123'); | |
| $stringObj->setValue('Andy protected'); | |
| print_r($stringObj->getCleanup()->doAction()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment