From 9d9a0dc3951014f2cb2e0ce6d114ecb59d059acd Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Fri, 31 May 2024 15:13:43 -0400 Subject: [PATCH] Don't cast nulls --- src/PHPFUI/ORM/Record.php | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/PHPFUI/ORM/Record.php b/src/PHPFUI/ORM/Record.php index 88512a6..898527d 100644 --- a/src/PHPFUI/ORM/Record.php +++ b/src/PHPFUI/ORM/Record.php @@ -474,31 +474,34 @@ public function loadFromSQL(string $sql, array $input = []) : bool // cast to correct values as ints, floats, etc are read in from PDO as strings foreach (static::$fields as $field => $row) { - switch ($row[1]) + if (null !== $this->current[$field]) // @phpstan-ignore-line { - case 'int': - if (\array_key_exists($field, $this->current)) - { - $this->current[$field] = (int)$this->current[$field]; - } + switch ($row[1]) + { + case 'int': + if (\array_key_exists($field, $this->current)) + { + $this->current[$field] = (int)$this->current[$field]; + } - break; + break; - case 'float': - if (\array_key_exists($field, $this->current)) - { - $this->current[$field] = (float)$this->current[$field]; - } + case 'float': + if (\array_key_exists($field, $this->current)) + { + $this->current[$field] = (float)$this->current[$field]; + } - break; + break; - case 'bool': - if (\array_key_exists($field, $this->current)) - { - $this->current[$field] = (bool)$this->current[$field]; - } + case 'bool': + if (\array_key_exists($field, $this->current)) + { + $this->current[$field] = (bool)$this->current[$field]; + } - break; + break; + } } }