Skip to content

Commit 5d52f33

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 0772251 commit 5d52f33

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
@@ -214,7 +214,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
214214
$line = [];
215215

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

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

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

251251
$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
252252
}

0 commit comments

Comments
 (0)