Skip to content

Commit 1db8dc7

Browse files
Merge branch '3.4' into 4.4
* 3.4: Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. [Debug] php 8 does not pass $context to error handlers. [Config] Removed implicit cast of ReflectionProperty to string. [Debug] Undefined variables raise a warning in php 8. [Debug] Skip test that would trigger a fatal error on php 8. Address deprecation of ReflectionType::getClass(). Properties $originalName and $mimeType are never null in UploadedFile
2 parents bd61027 + f609daf commit 1db8dc7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

PropertyAccessor.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,15 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
183183

184184
private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath, \Throwable $previous = null): void
185185
{
186-
// the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method)
187-
if (0 !== strpos($message, 'Argument ')) {
186+
if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) {
188187
return;
189188
}
190189

191-
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
190+
if (\PHP_VERSION_ID < 80000) {
191+
if (0 !== strpos($message, 'Argument ')) {
192+
return;
193+
}
194+
192195
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
193196
$pos += \strlen($delim);
194197
$j = strpos($message, ',', $pos);
@@ -197,6 +200,12 @@ private static function throwInvalidArgumentException(string $message, array $tr
197200

198201
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath), 0, $previous);
199202
}
203+
204+
if (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
205+
list(, $expectedType, $actualType) = $matches;
206+
207+
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given.', $expectedType, 'NULL' === $actualType ? 'null' : $actualType), 0, $previous);
208+
}
200209
}
201210

202211
/**
@@ -384,7 +393,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
384393
$result[self::VALUE] = $object->{$access[self::ACCESS_NAME]}();
385394
} catch (\TypeError $e) {
386395
// handle uninitialized properties in PHP >= 7
387-
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)) {
396+
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)) {
388397
throw new AccessException(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);
389398
}
390399

0 commit comments

Comments
 (0)