Skip to content

Commit 2abd699

Browse files
Merge branch '3.4' into 4.3
* 3.4: Fix failures on PHP 7.4
2 parents bb0c302 + 9ec5e22 commit 2abd699

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($message, $trace, $i, $pro
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
@@ -544,7 +544,7 @@ public function testThrowTypeError()
544544
public function testThrowTypeErrorWithNullArgument()
545545
{
546546
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
547-
$this->expectExceptionMessage('Expected argument of type "DateTime", "NULL" given');
547+
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
548548
$object = new TypeHinted();
549549

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

0 commit comments

Comments
 (0)