Well, you can write a __get
function to each of your classes that would handle such a conversion, but it's quite hacky. Something like this might work:
class HasInconsistentNaming {
var $fooBar = 1;
var $Somethingelse = 2;
function __get($var) {
$vars = get_class_vars(get_class($this));
foreach($vars as $key => $value) {
if(strtolower($var) == strtolower($key)) {
return $this->$key;
break;
}
}
return null;
}
}
Now, you can do this:
$newclass = new HasInconsistentNaming();
echo $newclass->foobar; // outputs 1
If you want to simplify your task a bit you can have your base classes inheriting from a class that provides this functionality. This way you don't have to write the function to each of your classes:
class CaseInsensitiveGetter {
function __get($var) {
$vars = get_class_vars(get_class($this));
foreach($vars as $key => $value) {
if(strtolower($var) == strtolower($key)) {
return $this->$key;
break;
}
}
return null;
}
}
class HasInconsistentNaming extends CaseInsensitiveGetter {
var $fooBar = 1;
var $Somethingelse = 2;
}
But I'd strongly discourage you from taking this approach. In the long run, it would be much smarter to just convert all variables into a consistent naming scheme.