I need to check if a property exists and this works:
class someClass {
protected $some_var
public static function checkProperty($property) {
if(!property_exists(get_class()) ) {
return true;
} else return false;
}
}
But now when I try to extend the class, it doesn’t work anymore.
class someChild extends someClass {
protected $child_property;
}
someChild::checkProperty('child_property'); // false
How do I get the functionality I want? I tried replacing get_class() with $this, self, static, nothing works.
I believe I’ve found the correct answer. For static methods, use
get_called_class().Perhaps
$thisworks for object methods.