Use self to indicate the current class. Not a class name .
Try using magic constants:
if(isset($user->$name) || property_exists(__CLASS__, $name)){
From php reference: __CLASS__
Class name. (Added in PHP 4.3.0). Starting with PHP 5, this constant returns the class name as declared (case sensitive). In PHP 4, its value is always decreasing. The class name includes the namespace in which it was declared (for example, Foo \ Bar). Please note that with PHP 5.4, CLASS also works in outline. When used in an attribute method, CLASS is the name of the class in which the attribute is used.
PHP manual
Example:
class Test { public function __construct(){ echo __CLASS__; } } $test = new Test();
Output:
Test
source share