From af36c341ac7ab4bb3abaeca443c9ca42622456d8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 22 May 2015 14:11:18 +0200 Subject: [PATCH] [Translation] fixed JSON loader on PHP 7 when file is empty --- .../Component/Translation/Loader/JsonFileLoader.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Translation/Loader/JsonFileLoader.php b/src/Symfony/Component/Translation/Loader/JsonFileLoader.php index 8327c63b57..09138835a6 100644 --- a/src/Symfony/Component/Translation/Loader/JsonFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/JsonFileLoader.php @@ -35,10 +35,13 @@ class JsonFileLoader extends ArrayLoader implements LoaderInterface throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } - $messages = json_decode(file_get_contents($resource), true); + $messages = array(); + if ($data = file_get_contents($resource)) { + $messages = json_decode($data, true); - if (0 < $errorCode = json_last_error()) { - throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode))); + if (0 < $errorCode = json_last_error()) { + throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode))); + } } if (null === $messages) {