src/Traits/ReflectionUtilities.php
public function getPropertyValue($className, $propertyName, $concreteClass = NULL, $options = []) {
        $callConstructor = (isset($options['callConstructor'])) ? (bool) $options['callConstructor'] : FALSE;
        $reflector = new ReflectionClass($className);

        //This is a default property
        if($concreteClass === NULL && $callConstructor === FALSE) {
            $properties = $reflector->getDefaultProperties();

            return (isset($properties[$propertyName])) ? $properties[$propertyName] : NULL;
        }

        //Return NULL if this class not has the given property
        if(!$reflector->hasProperty($propertyName)) {
            return NULL;
        }

        //Get reflector for property and set it accessible
        $propertyReflector = $reflector->getProperty($propertyName);
        $propertyReflector->setAccessible(TRUE);

        //If we give a concrete class returns the value from this class
        if($concreteClass !== NULL) {
            return $propertyReflector->getValue($concreteClass);
        }

        //Needs to call the class constructor
        if($callConstructor === TRUE) {
            $constructorParams = (isset($options['constructorParams'])) ? (array) $options['constructorParams'] : [];

            return $propertyReflector->getValue($reflector->newInstanceArgs($constructorParams));
        }

        //This should never happen
        //@codeCoverageIgnoreStart
        return NULL;
        //@codeCoverageIgnoreEnd
    }
public function getPropertyValue($className, $propertyName, $concreteClass = NULL, $options = []) {
        $callConstructor = (isset($options['callConstructor'])) ? (bool) $options['callConstructor'] : FALSE;
        $reflector = new ReflectionClass($className);

        //This is a default property
        if($concreteClass === NULL && $callConstructor === FALSE) {
            $properties = $reflector->getDefaultProperties();

            return (isset($properties[$propertyName])) ? $properties[$propertyName] : NULL;
        }

        //Return NULL if this class not has the given property
        if(!$reflector->hasProperty($propertyName)) {
            return NULL;
        }

        //Get reflector for property and set it accessible
        $propertyReflector = $reflector->getProperty($propertyName);
        $propertyReflector->setAccessible(TRUE);

        //If we give a concrete class returns the value from this class
        if($concreteClass !== NULL) {
            return $propertyReflector->getValue($concreteClass);
        }

        //Needs to call the class constructor
        if($callConstructor === TRUE) {
            $constructorParams = (isset($options['constructorParams'])) ? (array) $options['constructorParams'] : [];

            return $propertyReflector->getValue($reflector->newInstanceArgs($constructorParams));
        }

        //This should never happen
        //@codeCoverageIgnoreStart
        return NULL;
        //@codeCoverageIgnoreEnd
    }
public function getPropertyValue ( $ className , $ propertyName , $ concreteClass = NULL , $ options = [ ] ) { $ callConstructor = ( isset ( $ options [ 'callConstructor' ] ) ) ? ( bool ) $ options [ 'callConstructor' ] : FALSE ; $ reflector = new ReflectionClass ( $ className ) ; //This is a default property if ( $ concreteClass === NULL && $ callConstructor === FALSE ) { $ properties = $ reflector -> getDefaultProperties ( ) ; return ( isset ( $ properties [ $ propertyName ] ) ) ? $ properties [ $ propertyName ] : NULL ; } //Return NULL if this class not has the given property if ( ! $ reflector -> hasProperty ( $ propertyName ) ) { return NULL ; } //Get reflector for property and set it accessible $ propertyReflector = $ reflector -> getProperty ( $ propertyName ) ; $ propertyReflector -> setAccessible ( TRUE ) ; //If we give a concrete class returns the value from this class if ( $ concreteClass !== NULL ) { return $ propertyReflector -> getValue ( $ concreteClass ) ; } //Needs to call the class constructor if ( $ callConstructor === TRUE ) { $ constructorParams = ( isset ( $ options [ 'constructorParams' ] ) ) ? ( array ) $ options [ 'constructorParams' ] : [ ] ; return $ propertyReflector -> getValue ( $ reflector -> newInstanceArgs ( $ constructorParams ) ) ; } //This should never happen //@codeCoverageIgnoreStart return NULL ; //@codeCoverageIgnoreEnd }
Read a property value from a given class or concrete object. This function can handle automatic creation
of new instances of the given class.

If no concrete object provided and the 'callConstructor' option is FALSE reads the property default value
from the class.

If a concrete object is provided returns the property value from the given concrete object.

If the 'callConstructor' is TRUE and concrete object is not provided this method try to instantiate a
new object from thi given class using the 'constructorParams' option.

options:
'callConstructor' => bool
'constructorParams' => array (key is variable name, value is the value of the variable)

@param string $className The FQCN
@param string $propertyName The property name
@param object|NULL $concreteClass Optionally concrete class
@param array $options Options defined as an array

@return NULL|mixed
Read a property value from a given class or concrete object . This function can handle automatic creation of new instances of the given class .