Skip to content

Commit 9ec5e22

Browse files
Fix failures on PHP 7.4
1 parent 5bd3b72 commit 9ec5e22

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
@@ -260,13 +260,14 @@ private static function throwInvalidArgumentException($message, $trace, $i)
260260
return;
261261
}
262262

263-
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file'] && \array_key_exists(0, $trace[$i]['args'])) {
263+
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
264264
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
265265
$pos += \strlen($delim);
266-
$type = $trace[$i]['args'][0];
267-
$type = \is_object($type) ? \get_class($type) : \gettype($type);
266+
$j = strpos($message, ',', $pos);
267+
$type = substr($message, 2 + $j, strpos($message, ' given', $j) - $j - 2);
268+
$message = substr($message, $pos, $j - $pos);
268269

269-
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given', substr($message, $pos, strpos($message, ',', $pos) - $pos), $type));
270+
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given', $message, 'NULL' === $type ? 'null' : $type));
270271
}
271272
}
272273

Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public function testThrowTypeError()
532532
public function testThrowTypeErrorWithNullArgument()
533533
{
534534
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
535-
$this->expectExceptionMessage('Expected argument of type "DateTime", "NULL" given');
535+
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
536536
$object = new TypeHinted();
537537

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

0 commit comments

Comments
 (0)