Skip to content

Commit

Permalink
Don't cast nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
phpfui committed May 31, 2024
1 parent d4658c2 commit 9d9a0dc
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/PHPFUI/ORM/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 9d9a0dc

Please sign in to comment.