Last active
July 9, 2017 21:55
-
-
Save terales/b8054feabebfeb2a2dc4437d86e4f914 to your computer and use it in GitHub Desktop.
DeprecateProperties for embedding into blog post
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// from https://github.com/terales/deprecate-properties/blob/master/DeprecateProperties.php | |
class DeprecateProperties | |
{ | |
private $dataObject; | |
private $deprecatedProps = array('db', 'user', 'payment'); | |
public function __construct() | |
{ | |
// Use what we had in the codebase | |
$this->dataObject = new stdClass(); | |
} | |
public function __set($name, $value) | |
{ | |
$this->logIfDeprecatedProperty($name, 'write'); | |
$this->dataObject->{$name} = $value; | |
} | |
public function __get($name) | |
{ | |
$this->logIfDeprecatedProperty($name, 'read'); | |
return $this->dataObject->{$name}; | |
} | |
private function logIfDeprecatedProperty($property, $type) | |
{ | |
if (in_array($property, $this->deprecatedProps)) { | |
echo "${type} deprecated property '${property}'\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment