Skip to content

Commit 9d9a0dc

Browse files
committed
Don't cast nulls
1 parent d4658c2 commit 9d9a0dc

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/PHPFUI/ORM/Record.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,31 +474,34 @@ public function loadFromSQL(string $sql, array $input = []) : bool
474474
// cast to correct values as ints, floats, etc are read in from PDO as strings
475475
foreach (static::$fields as $field => $row)
476476
{
477-
switch ($row[1])
477+
if (null !== $this->current[$field]) // @phpstan-ignore-line
478478
{
479-
case 'int':
480-
if (\array_key_exists($field, $this->current))
481-
{
482-
$this->current[$field] = (int)$this->current[$field];
483-
}
479+
switch ($row[1])
480+
{
481+
case 'int':
482+
if (\array_key_exists($field, $this->current))
483+
{
484+
$this->current[$field] = (int)$this->current[$field];
485+
}
484486

485-
break;
487+
break;
486488

487-
case 'float':
488-
if (\array_key_exists($field, $this->current))
489-
{
490-
$this->current[$field] = (float)$this->current[$field];
491-
}
489+
case 'float':
490+
if (\array_key_exists($field, $this->current))
491+
{
492+
$this->current[$field] = (float)$this->current[$field];
493+
}
492494

493-
break;
495+
break;
494496

495-
case 'bool':
496-
if (\array_key_exists($field, $this->current))
497-
{
498-
$this->current[$field] = (bool)$this->current[$field];
499-
}
497+
case 'bool':
498+
if (\array_key_exists($field, $this->current))
499+
{
500+
$this->current[$field] = (bool)$this->current[$field];
501+
}
500502

501-
break;
503+
break;
504+
}
502505
}
503506
}
504507

0 commit comments

Comments
 (0)