Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created December 12, 2012 19:44
Show Gist options
  • Select an option

  • Save dongilbert/4270918 to your computer and use it in GitHub Desktop.

Select an option

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.
<?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