Skip to content

Instantly share code, notes, and snippets.

@terales
Last active July 9, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terales/b8054feabebfeb2a2dc4437d86e4f914 to your computer and use it in GitHub Desktop.
Save terales/b8054feabebfeb2a2dc4437d86e4f914 to your computer and use it in GitHub Desktop.
DeprecateProperties for embedding into blog post
<? 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