You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 3.4 branch.
Discussion
----------
[PropertyAccess] Parse php 8 TypeErrors correctly
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | #36872
| License | MIT
| Doc PR | N/A
The wording of `TypeError` messages has changed in php 8. Since `PropertyAccessor` parses those messages, the logic needed some adjustments.
Commits
-------
7100c3c [PropertyAccess] Parse php 8 TypeErrors correctly.
// the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method)
259
-
if (0 !== strpos($message, 'Argument ')) {
258
+
if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) {
260
259
return;
261
260
}
262
261
263
-
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
262
+
if (\PHP_VERSION_ID < 80000) {
263
+
if (0 !== strpos($message, 'Argument ')) {
264
+
return;
265
+
}
266
+
264
267
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
if (preg_match((sprintf('/^Return value of %s::%s\(\) must be of the type (\w+), null returned$/', preg_quote(\get_class($object)), $access[self::ACCESS_NAME])), $e->getMessage(), $matches)) {
483
+
if (preg_match((sprintf('/^Return value of %s::%s\(\) must be of (?:the )?type (\w+), null returned$/', preg_quote(\get_class($object)), $access[self::ACCESS_NAME])), $e->getMessage(), $matches)) {
475
484
thrownewAccessException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', \get_class($object), $access[self::ACCESS_NAME], $matches[1]), 0, $e);
0 commit comments