Created
December 12, 2012 19:44
-
-
Save dongilbert/4270918 to your computer and use it in GitHub Desktop.
Abstract class containing magic __set and __get methods to alleviate B/C issues with removing underscore from protected properties.
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 | |
| abstract class JFixProtected | |
| { | |
| public function __set($name, $value) | |
| { | |
| $name = $this->cleanPropertyName($name); | |
| $this->$name = $value; | |
| } | |
| public function __get($name) | |
| { | |
| $name = $this->cleanPropertyName($name); | |
| return $this->$name ?: null; | |
| } | |
| private function cleanPropertyName($name) | |
| { | |
| if (strpos('_', $name) === 0) | |
| { | |
| $name = str_replace('_', '', $name); | |
| } | |
| return $name; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment