Skip to content

Commit

Permalink
Fix failures on PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 1, 2019
1 parent abc2880 commit a94e76a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Expand Up @@ -271,7 +271,7 @@ private function generateItems(array $keys)
public static function throwOnRequiredClass($class)
{
$e = new \ReflectionException("Class $class does not exist");
$trace = $e->getTrace();
$trace = debug_backtrace();
$autoloadFrame = [
'function' => 'spl_autoload_call',
'args' => [$class],
Expand Down
Expand Up @@ -72,7 +72,7 @@ public function isFresh($timestamp)
spl_autoload_register(__CLASS__.'::throwOnRequiredClass');
}
$autoloadedClass = self::$autoloadedClass;
self::$autoloadedClass = $this->resource;
self::$autoloadedClass = ltrim($this->resource, '\\');

try {
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
Expand Down Expand Up @@ -161,7 +161,7 @@ public static function throwOnRequiredClass($class, \Exception $previous = null)
throw $e;
}

$trace = $e->getTrace();
$trace = debug_backtrace();
$autoloadFrame = [
'function' => 'spl_autoload_call',
'args' => [$class],
Expand Down
9 changes: 5 additions & 4 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Expand Up @@ -260,13 +260,14 @@ private static function throwInvalidArgumentException($message, $trace, $i)
return;
}

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

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

Expand Down
Expand Up @@ -532,7 +532,7 @@ public function testThrowTypeError()
public function testThrowTypeErrorWithNullArgument()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Expected argument of type "DateTime", "NULL" given');
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
$object = new TypeHinted();

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

0 comments on commit a94e76a

Please sign in to comment.