From 2f05ef4a0bf810e5b54b42c67dd5ec39b6d365a5 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 15 Jan 2024 18:04:36 +0000 Subject: [PATCH] [core] cleanup --- core/imageboard/image.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index f3c0ebba..732da076 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -19,9 +19,6 @@ function pop_val(array &$row, string $name): mixed { $value = $row[$name]; unset($row[$name]); - if(is_null($value)) { - return null; - } return $value; } function pop_int(array &$row, string $name): ?int @@ -95,6 +92,15 @@ class Image implements \ArrayAccess public function __construct(?array $row = null) { if (!is_null($row)) { + // some databases return both key=>value and numeric indices, + // we only want the key=>value ones + foreach ($row as $name => $value) { + if (is_numeric($name)) { + unset($row[$name]); + } + } + + // pull out known fields $this->id = pop_int($row, 'id'); $this->hash = pop_val($row, 'hash'); $this->filename = pop_val($row, 'filename'); @@ -117,9 +123,6 @@ class Image implements \ArrayAccess // Any remaining fields are dynamic properties foreach ($row as $name => $value) { - if (is_numeric($name)) { - continue; - } if(property_exists($this, $name)) { throw new \Exception("Property $name already exists on Image"); }