Skip to content

Commit bafdc8c

Browse files
Merge branch '4.3' into 4.4
* 4.3: Fix failures on PHP 7.4
2 parents 4df120c + 2abd699 commit bafdc8c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

PropertyAccessor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,14 @@ private static function throwInvalidArgumentException(string $message, array $tr
188188
return;
189189
}
190190

191-
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file'] && \array_key_exists(0, $trace[$i]['args'])) {
191+
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
192192
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
193193
$pos += \strlen($delim);
194-
$type = $trace[$i]['args'][0];
195-
$type = \is_object($type) ? \get_class($type) : \gettype($type);
194+
$j = strpos($message, ',', $pos);
195+
$type = substr($message, 2 + $j, strpos($message, ' given', $j) - $j - 2);
196+
$message = substr($message, $pos, $j - $pos);
196197

197-
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', substr($message, $pos, strpos($message, ',', $pos) - $pos), $type, $propertyPath));
198+
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath));
198199
}
199200
}
200201

Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public function testThrowTypeError()
546546
public function testThrowTypeErrorWithNullArgument()
547547
{
548548
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
549-
$this->expectExceptionMessage('Expected argument of type "DateTime", "NULL" given');
549+
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
550550
$object = new TypeHinted();
551551

552552
$this->propertyAccessor->setValue($object, 'date', null);

0 commit comments

Comments
 (0)