Skip to content

Commit b7deefa

Browse files
committed
refactor: fix TypeError in BaseUtils
1) CodeIgniter\Database\Live\DbUtilsTest::testUtilsCSVFromResult TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, int given /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php:217 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/DbUtilsTest.php:186 2) CodeIgniter\Database\Live\DbUtilsTest::testUtilsXMLFromResult TypeError: xml_convert(): Argument #1 ($str) must be of type string, int given, called in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php on line 249 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/xml_helper.php:20 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseUtils.php:249 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/DbUtilsTest.php:199
1 parent 0ee570c commit b7deefa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

system/Database/BaseUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
212212
$line = [];
213213

214214
foreach ($row as $item) {
215-
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
215+
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, (string) $item) . $enclosure;
216216
}
217217

218218
$out .= implode($delim, $line) . $newline;
@@ -244,7 +244,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
244244
$xml .= $tab . '<' . $element . '>' . $newline;
245245

246246
foreach ($row as $key => $val) {
247-
$val = (! empty($val)) ? xml_convert($val) : '';
247+
$val = (! empty($val)) ? xml_convert((string) $val) : '';
248248

249249
$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
250250
}

0 commit comments

Comments
 (0)