Reputation: 14844
suppose I have two classes
class A extends class B
class A has its own fields class B has its own fields
since class A extends B, class A also contains the fields of B
Is there a way to get a list of fields that are only for class A and not fields that are inherited from B since calling get_object_vars()
on an object of class A would also return fields from class B
Upvotes: 2
Views: 1399
Reputation: 1852
You can do:
array_diff(get_object_vars($objectA), get_object_vars($objectB));
Edit, you can also do the same with classes:
array_diff(get_class_vars(CLASS A), get_class_vars(CLASS B));
Upvotes: 3