kamikaze_pilot
kamikaze_pilot

Reputation: 14844

php get class/object vars and inheritance

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

Answers (1)

zzarbi
zzarbi

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

Related Questions