Getting list of sub and super class member variables

Getting list of sub and super class member variables

On my project, I need to collect the member variables of the classes that I am working on.
But, since, the classes have common member variables like date_created and date_modified and others, I have Abstract class for those member variables and their setters and getters
I have been using get_class_vars for such cases, but I want to call this from the parent and be able to access the member variables at run time. which was a problem, it would collect only the parent member variables:

        $classProperties = array();
        $classProperties['vars'] = get_class_vars(get_class($this));

But this hasn’t work.
Then I used the reflection method:

        $child_reflection = new ReflectionClass($this);
        $child_properties = $child_reflection->getdefaultProperties();
        $parent_reflection = new ReflectionClass(__CLASS__);
        $parent_properties = $parent_reflection->getdefaultProperties();
        $class_properties['vars'] = array_merge($child_properties
, $parent_properties);

This would give all properties for the class. In this case it should be up to the developer to limit the access and manipulate the use of the properties not to loose the semantics of having them :-)

d i s   i z – IT!

See how you would solve these known algorithm problems

Get maximum occurring character

Implement Queue Using two Stacks – JavaScript algorithm

binary tree problems with solution

Changing decimal number to its binary equivalent

find longest word in the sentence

Find the first occurence of number in the sorted array

String Ordered Permutation Algorithm Problem

Find K Complementary numbers from array Java implementation

Check if two strings are anagrams or not

Find the pairs that makes K Complementary in the given array java solution

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*