lib/RTTI.php
static function setAttributes(
		array $map
		, &$obj
		, $visibilityFlags = null
		, $setterPrefix = 'set'
		, $useCamelCase = true
		) {
		$flags = null === $visibilityFlags ? self::allFlags() : $visibilityFlags;
		$reflectionObject = new \ReflectionObject( $obj );
		$currentClass = new \ReflectionClass( $obj );
		while ( $currentClass !== false && ! $currentClass->isInterface() ) {
		
			$properties = $currentClass->getProperties( $flags );
				
			foreach ( $properties as $property ) {
				
				$attributeName = $property->getName();
				$methodName = $setterPrefix .
					( $useCamelCase ? self::mb_ucfirst( $attributeName ) : $attributeName );
				
				if ( $property->isPrivate() || $property->isProtected() ) {
					
					if ( $reflectionObject->hasMethod( $methodName ) ) {
						
						$method = $reflectionObject->getMethod( $methodName );
						if ( $method->isPublic() && array_key_exists( $attributeName, $map ) ) {
							$method->invoke( $obj, $map[ $attributeName ] );
						}
					}
					
				} else { // public
					try {
						if ( array_key_exists( $attributeName, $map ) ) {
							$obj->{ $attributeName } = $map[ $attributeName ];
						}
					} catch ( \Exception $e ) {
						// Ignore
					}
				}
			}
			
			// No properties? -> try to retrieve only public properties
			if ( count( $properties ) < 1 ) {
				$properties = get_object_vars( $obj );
				foreach ( $properties as $attributeName => $v ) {
					if ( array_key_exists( $attributeName, $map ) ) { 
						try {
							$obj->{ $attributeName } = $map[ $attributeName ];
						} catch ( \Exception $e ) {
							// Ignore
						}
					}
				}
			}			
			
			$currentClass = $currentClass->getParentClass();
		}
	}
static function setAttributes(
		array $map
		, &$obj
		, $visibilityFlags = null
		, $setterPrefix = 'set'
		, $useCamelCase = true
		) {
		$flags = null === $visibilityFlags ? self::allFlags() : $visibilityFlags;
		$reflectionObject = new \ReflectionObject( $obj );
		$currentClass = new \ReflectionClass( $obj );
		while ( $currentClass !== false && ! $currentClass->isInterface() ) {
		
			$properties = $currentClass->getProperties( $flags );
				
			foreach ( $properties as $property ) {
				
				$attributeName = $property->getName();
				$methodName = $setterPrefix .
					( $useCamelCase ? self::mb_ucfirst( $attributeName ) : $attributeName );
				
				if ( $property->isPrivate() || $property->isProtected() ) {
					
					if ( $reflectionObject->hasMethod( $methodName ) ) {
						
						$method = $reflectionObject->getMethod( $methodName );
						if ( $method->isPublic() && array_key_exists( $attributeName, $map ) ) {
							$method->invoke( $obj, $map[ $attributeName ] );
						}
					}
					
				} else { // public
					try {
						if ( array_key_exists( $attributeName, $map ) ) {
							$obj->{ $attributeName } = $map[ $attributeName ];
						}
					} catch ( \Exception $e ) {
						// Ignore
					}
				}
			}
			
			// No properties? -> try to retrieve only public properties
			if ( count( $properties ) < 1 ) {
				$properties = get_object_vars( $obj );
				foreach ( $properties as $attributeName => $v ) {
					if ( array_key_exists( $attributeName, $map ) ) { 
						try {
							$obj->{ $attributeName } = $map[ $attributeName ];
						} catch ( \Exception $e ) {
							// Ignore
						}
					}
				}
			}			
			
			$currentClass = $currentClass->getParentClass();
		}
	}
static function setAttributes ( array $ map , & $ obj , $ visibilityFlags = null , $ setterPrefix = 'set' , $ useCamelCase = true ) { $ flags = null === $ visibilityFlags ? self :: allFlags ( ) : $ visibilityFlags ; $ reflectionObject = new \ ReflectionObject ( $ obj ) ; $ currentClass = new \ ReflectionClass ( $ obj ) ; while ( $ currentClass !== false && ! $ currentClass -> isInterface ( ) ) { $ properties = $ currentClass -> getProperties ( $ flags ) ; foreach ( $ properties as $ property ) { $ attributeName = $ property -> getName ( ) ; $ methodName = $ setterPrefix . ( $ useCamelCase ? self :: mb_ucfirst ( $ attributeName ) : $ attributeName ) ; if ( $ property -> isPrivate ( ) || $ property -> isProtected ( ) ) { if ( $ reflectionObject -> hasMethod ( $ methodName ) ) { $ method = $ reflectionObject -> getMethod ( $ methodName ) ; if ( $ method -> isPublic ( ) && array_key_exists ( $ attributeName , $ map ) ) { $ method -> invoke ( $ obj , $ map [ $ attributeName ] ) ; } } } else { // public try { if ( array_key_exists ( $ attributeName , $ map ) ) { $ obj -> { $ attributeName } = $ map [ $ attributeName ] ; } } catch ( \ Exception $ e ) { // Ignore } } } // No properties? -> try to retrieve only public properties if ( count ( $ properties ) < 1 ) { $ properties = get_object_vars ( $ obj ) ; foreach ( $ properties as $ attributeName => $ v ) { if ( array_key_exists ( $ attributeName , $ map ) ) { try { $ obj -> { $ attributeName } = $ map [ $ attributeName ] ; } catch ( \ Exception $ e ) { // Ignore } } } } $ currentClass = $ currentClass -> getParentClass ( ) ; } }
Set the attribute values of a object.

@param array		$map				A map with the attribute names and values to be changed.

@param object	$obj				The object to be changed.

@param int		$visibilityFlags 	Filter visibility flags. Can be added.
Example: RTTI::IS_PRIVATE | RTTI::IS_PROTECTED
Optional, defaults to RTTI::allFlags.

@param string	$setterPrefix		The prefix for setter public methods (defaults to 'set').

@param bool		$useCamelCase		If true, private and protected attributes will be set by
camelCase public methods (default true).
Set the attribute values of a object .