Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #34902 [PropertyAccess] forward caught exception (xabbuh)
This PR was merged into the 3.4 branch.

Discussion
----------

[PropertyAccess] forward caught exception

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34899
| License       | MIT
| Doc PR        |

Commits
-------

98e18d3 forward caught exception
  • Loading branch information
nicolas-grekas committed Dec 10, 2019
2 parents bf877b8 + 98e18d3 commit 56bfbd8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Expand Up @@ -229,7 +229,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
$value = $zval[self::VALUE];
}
} catch (\TypeError $e) {
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0);
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $e);

// It wasn't thrown in this class so rethrow it
throw $e;
Expand All @@ -253,7 +253,7 @@ public static function handleError($type, $message, $file, $line, $context = [])
return null !== self::$previousErrorHandler && false !== \call_user_func(self::$previousErrorHandler, $type, $message, $file, $line, $context);
}

private static function throwInvalidArgumentException($message, $trace, $i)
private static function throwInvalidArgumentException($message, $trace, $i, $previous = null)
{
// the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method)
if (0 !== strpos($message, 'Argument ')) {
Expand All @@ -267,7 +267,7 @@ private static function throwInvalidArgumentException($message, $trace, $i)
$type = substr($message, 2 + $j, strpos($message, ' given', $j) - $j - 2);
$message = substr($message, $pos, $j - $pos);

throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given', $message, 'NULL' === $type ? 'null' : $type));
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given', $message, 'NULL' === $type ? 'null' : $type), 0, $previous);
}
}

Expand Down

0 comments on commit 56bfbd8

Please sign in to comment.