private static function processTypeErrorOnGetValue($object, string $property, \TypeError $error): void
    {
        if (0 !== strpos($error->getMessage(), 'Return value of ')) {
            return;
        }

        $pos = strpos($error->getMessage(), $delim = 'must be of the type ') ?: (strpos($error->getMessage(), $delim = 'must be an instance of ') ?: strpos($error->getMessage(), $delim = 'must implement interface '));
        if (false !== $pos) {
            $ro = new \ReflectionObject($object);
            $rp = $ro->getProperty($property);
            $rp->setAccessible(true);
            $pos += strlen($delim);
            $actualValue = $rp->getValue($object);
            $expectedType = substr($error->getMessage(), $pos, (int) strpos($error->getMessage(), ',', $pos) - $pos);

            if (null === $actualValue) {
                throw new UninitializedPropertyException($object, $property, $expectedType);
            }

            $actualType = \is_object($actualValue) ? \get_class($actualValue) : \gettype($actualValue);

            // Until we are using strongly typed variables this should not happen.
            throw new UnexpectedValueException($object, $property, $expectedType, $actualType);
        }
    }
private static function processTypeErrorOnGetValue($object, string $property, \TypeError $error): void
    {
        if (0 !== strpos($error->getMessage(), 'Return value of ')) {
            return;
        }

        $pos = strpos($error->getMessage(), $delim = 'must be of the type ') ?: (strpos($error->getMessage(), $delim = 'must be an instance of ') ?: strpos($error->getMessage(), $delim = 'must implement interface '));
        if (false !== $pos) {
            $ro = new \ReflectionObject($object);
            $rp = $ro->getProperty($property);
            $rp->setAccessible(true);
            $pos += strlen($delim);
            $actualValue = $rp->getValue($object);
            $expectedType = substr($error->getMessage(), $pos, (int) strpos($error->getMessage(), ',', $pos) - $pos);

            if (null === $actualValue) {
                throw new UninitializedPropertyException($object, $property, $expectedType);
            }

            $actualType = \is_object($actualValue) ? \get_class($actualValue) : \gettype($actualValue);

            // Until we are using strongly typed variables this should not happen.
            throw new UnexpectedValueException($object, $property, $expectedType, $actualType);
        }
    }
private static function processTypeErrorOnGetValue ( $ object , string $ property , \ TypeError $ error ) : void { if ( 0 !== strpos ( $ error -> getMessage ( ) , 'Return value of ' ) ) { return ; } $ pos = strpos ( $ error -> getMessage ( ) , $ delim = 'must be of the type ' ) ? : ( strpos ( $ error -> getMessage ( ) , $ delim = 'must be an instance of ' ) ? : strpos ( $ error -> getMessage ( ) , $ delim = 'must implement interface ' ) ) ; if ( false !== $ pos ) { $ ro = new \ ReflectionObject ( $ object ) ; $ rp = $ ro -> getProperty ( $ property ) ; $ rp -> setAccessible ( true ) ; $ pos += strlen ( $ delim ) ; $ actualValue = $ rp -> getValue ( $ object ) ; $ expectedType = substr ( $ error -> getMessage ( ) , $ pos , ( int ) strpos ( $ error -> getMessage ( ) , ',' , $ pos ) - $ pos ) ; if ( null === $ actualValue ) { throw new UninitializedPropertyException ( $ object , $ property , $ expectedType ) ; } $ actualType = \ is_object ( $ actualValue ) ? \ get_class ( $ actualValue ) : \ gettype ( $ actualValue ) ; // Until we are using strongly typed variables this should not happen. throw new UnexpectedValueException ( $ object , $ property , $ expectedType , $ actualType ) ; } }
Processes type error exception on value get.

Throws better, more meaningful exception if a value is uninitialised
or initialized with an incorrect value on an object.

Based on PropertyAccessor::throwInvalidArgumentException().

@param object $object
@param string $property
@param \TypeError $error

@see \Symfony\Component\PropertyAccess\PropertyAccessor::throwInvalidArgumentException()
Processes type error exception on value get .