From d4bf288fed65d5ac2e2c913ce532f34d9d902010 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Fri, 7 Jun 2013 13:43:07 +0400 Subject: [PATCH] Fix bug with wrong if statement. Add TODO with use log error message. --- File.class.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/File.class.php b/File.class.php index e430728..da9b374 100644 --- a/File.class.php +++ b/File.class.php @@ -12,17 +12,19 @@ abstract class File public static function getInstance($data = null) { $instance = new static; - if (!(is_null($data) && $data == '')) { + if (!(is_null($data) || $data == '')) { if (!is_array($data)) { - $data = json_decode($data, true); + $data = json_decode($data, true); if (json_last_error() != JSON_ERROR_NONE) { - //TODO: decrease warning level - throw new ErrorException('Unable to convert json-string to array. Data ' . print_r($data, true)); + //TODO: подумать над тем, чтобы субмодуль не был связан с классом приложения - вынести отдельно логгер для этого класса + ErrorMessage::log('Unable to convert json-string to array. Data ' . print_r($data, true)); } } - foreach ($data as $attribute_name => $attribute_value) { - if (property_exists($instance, $attribute_name)) { - $instance->{$attribute_name} = $attribute_value; + if (is_array($data)) { + foreach ($data as $attribute_name => $attribute_value) { + if (property_exists($instance, $attribute_name)) { + $instance->{$attribute_name} = $attribute_value; + } } } }