src/CallProtectedMethodTrait.php
public function callProtectedMethod(
        $object,
        string $method,
        array $arguments = []
    ) {
        if (!is_object($object)) {
            $msg = $this->getErrorMessage(1, __METHOD__, $object);
            throw new InvalidArgumentException($msg);
        }
        $class = new ReflectionClass($object);
        $method = $class->getMethod($method);
        $method->setAccessible(true);
        return $method->invokeArgs($object, $arguments);
    }
public function callProtectedMethod(
        $object,
        string $method,
        array $arguments = []
    ) {
        if (!is_object($object)) {
            $msg = $this->getErrorMessage(1, __METHOD__, $object);
            throw new InvalidArgumentException($msg);
        }
        $class = new ReflectionClass($object);
        $method = $class->getMethod($method);
        $method->setAccessible(true);
        return $method->invokeArgs($object, $arguments);
    }
public function callProtectedMethod ( $ object , string $ method , array $ arguments = [ ] ) { if ( ! is_object ( $ object ) ) { $ msg = $ this -> getErrorMessage ( 1 , __METHOD__ , $ object ) ; throw new InvalidArgumentException ( $ msg ) ; } $ class = new ReflectionClass ( $ object ) ; $ method = $ class -> getMethod ( $ method ) ; $ method -> setAccessible ( true ) ; return $ method -> invokeArgs ( $ object , $ arguments ) ; }
Calls a protected or private method and returns its result.

@param object $object    The instance containing the method to call.
@param string $method    The method name.
@param array  $arguments Arguments to pass to the method.

@throws InvalidArgumentException Non-object passed as first parameter.

@return mixed The return value of the method call.
Calls a protected or private method and returns its result .