src/Alg/Object/MethodFactory.php
public static function callObjectMethod( $object, $methodName, $parameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
	{
		if( !is_object( $object ) )
			throw new InvalidArgumentException( 'Invalid object' );

		$reflection	= new ReflectionObject( $object );												//  get Object Reflection
		if( $checkMethod && !$reflection->hasMethod( $methodName ) )								//  called Method is not existing
		{
			$message	= 'Method '.$reflection->getName().'::'.$methodName.' is not existing';		//  prepare Exception Message
			throw new BadMethodCallException( $message );											//  throw Exception
		}

		if( $reflection->hasMethod( $methodName ) )
		{
			$method		= $reflection->getMethod( $methodName );
		}
		else{
			$method		= $reflection->getMethod( '__call' );
			$parameters	= array(
				$methodName,
				$parameters
			);
		}
		if( $allowProtected && version_compare( PHP_VERSION, '5.3.2' ) >= 0 )
			$method->setAccessible( TRUE );															//  @see http://php.net/manual/de/reflectionmethod.setaccessible.php
		if( $parameters )																			//  if Method Parameters are set
			return $method->invokeArgs( $object, $parameters );										//  invoke Method with Parameters
		return $method->invoke( $object );															//  else invoke Method without Parameters
	}
public static function callObjectMethod( $object, $methodName, $parameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
	{
		if( !is_object( $object ) )
			throw new InvalidArgumentException( 'Invalid object' );

		$reflection	= new ReflectionObject( $object );												//  get Object Reflection
		if( $checkMethod && !$reflection->hasMethod( $methodName ) )								//  called Method is not existing
		{
			$message	= 'Method '.$reflection->getName().'::'.$methodName.' is not existing';		//  prepare Exception Message
			throw new BadMethodCallException( $message );											//  throw Exception
		}

		if( $reflection->hasMethod( $methodName ) )
		{
			$method		= $reflection->getMethod( $methodName );
		}
		else{
			$method		= $reflection->getMethod( '__call' );
			$parameters	= array(
				$methodName,
				$parameters
			);
		}
		if( $allowProtected && version_compare( PHP_VERSION, '5.3.2' ) >= 0 )
			$method->setAccessible( TRUE );															//  @see http://php.net/manual/de/reflectionmethod.setaccessible.php
		if( $parameters )																			//  if Method Parameters are set
			return $method->invokeArgs( $object, $parameters );										//  invoke Method with Parameters
		return $method->invoke( $object );															//  else invoke Method without Parameters
	}
public static function callObjectMethod ( $ object , $ methodName , $ parameters = array ( ) , $ checkMethod = TRUE , $ allowProtected = FALSE ) { if ( ! is_object ( $ object ) ) throw new InvalidArgumentException ( 'Invalid object' ) ; $ reflection = new ReflectionObject ( $ object ) ; //  get Object Reflection if ( $ checkMethod && ! $ reflection -> hasMethod ( $ methodName ) ) //  called Method is not existing { $ message = 'Method ' . $ reflection -> getName ( ) . '::' . $ methodName . ' is not existing' ; //  prepare Exception Message throw new BadMethodCallException ( $ message ) ; //  throw Exception } if ( $ reflection -> hasMethod ( $ methodName ) ) { $ method = $ reflection -> getMethod ( $ methodName ) ; } else { $ method = $ reflection -> getMethod ( '__call' ) ; $ parameters = array ( $ methodName , $ parameters ) ; } if ( $ allowProtected && version_compare ( PHP_VERSION , '5.3.2' ) >= 0 ) $ method -> setAccessible ( TRUE ) ; //  @see http://php.net/manual/de/reflectionmethod.setaccessible.php if ( $ parameters ) //  if Method Parameters are set return $ method -> invokeArgs ( $ object , $ parameters ) ; //  invoke Method with Parameters return $ method -> invoke ( $ object ) ; //  else invoke Method without Parameters }
Calls Class or Object Method.
@access		public
@static
@param		object			$object				Object to call Method of
@param		string			$methodName			Name of Method to call
@param		array			$parameters			List of Parameters for Method Call
@param		boolean			$checkMethod		Flag: check if methods exists by default, disable for classes using __call
@param		boolean			$allowProtected		Flag: allow invoking protected and private methods (PHP 5.3.2+), default: no
@return		mixed			Result of called Method
@throws		InvalidArgumentException			if no object is given
@throws		BadMethodCallException				if an invalid Method is called
Calls Class or Object Method .