Skip to content

Commit ae4f2e8

Browse files
committed
Fix PHP8.2 str_split function returns empty arrays for empty strings
1 parent 2fb1c01 commit ae4f2e8

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

include/barcodes/qrcode.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ public function __construct($code, $eclevel = 'L') {
638638
$barcode_array['bcode'] = array();
639639
foreach ($qrTab as $line) {
640640
$arrAdd = array();
641-
foreach (str_split($line) as $char) {
641+
$chars = function_exists('mb_str_split') ? mb_str_split($line) : str_split($line);
642+
foreach ($chars as $char) {
642643
$arrAdd[] = ($char=='1')?1:0;
643644
}
644645
$barcode_array['bcode'][] = $arrAdd;
@@ -1307,7 +1308,8 @@ protected function eatNum() {
13071308
return $this->eatAn();
13081309
}
13091310
}
1310-
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
1311+
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
1312+
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, $data);
13111313
return $run;
13121314
}
13131315

@@ -1346,7 +1348,8 @@ protected function eatAn() {
13461348
return $this->eat8();
13471349
}
13481350
}
1349-
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
1351+
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
1352+
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, $data);
13501353
return $run;
13511354
}
13521355

@@ -1359,7 +1362,8 @@ protected function eatKanji() {
13591362
while($this->identifyMode($p) == QR_MODE_KJ) {
13601363
$p += 2;
13611364
}
1362-
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
1365+
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
1366+
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, $data);
13631367
$run = $p;
13641368
return $run;
13651369
}
@@ -1409,7 +1413,8 @@ protected function eat8() {
14091413
}
14101414
}
14111415
$run = $p;
1412-
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
1416+
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
1417+
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, $data);
14131418
return $run;
14141419
}
14151420

include/tcpdf_fonts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
20042004
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
20052005
$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
20062006
} else {
2007-
$chars = str_split($str);
2007+
$chars = function_exists('mb_str_split') ? mb_str_split($str) : str_split($str);
20082008
$carr = array_map('ord', $chars);
20092009
}
20102010
if (is_array($currentfont['subsetchars']) && is_array($carr)) {

tcpdf_barcodes_1d.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,8 +2179,8 @@ protected function barcode_imb_pre($code) {
21792179
if (!preg_match('/^[fadtFADT]{65}$/', $code) == 1) {
21802180
return false;
21812181
}
2182-
$characters = str_split(strtolower($code), 1);
2183-
// build bars
2182+
$characters = function_exists('mb_str_split') ? mb_str_split(strtolower($code), 1) : str_split(strtolower($code), 1);
2183+
// build bars
21842184
$k = 0;
21852185
$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
21862186
for ($i = 0; $i < 65; ++$i) {

tcpdf_barcodes_2d.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ public function setBarcode($code, $type) {
320320
$this->barcode_array['num_cols'] = strlen($rows[0]);
321321
$this->barcode_array['bcode'] = array();
322322
foreach ($rows as $r) {
323-
$this->barcode_array['bcode'][] = str_split($r, 1);
324-
}
323+
$this->barcode_array['bcode'][] = function_exists('mb_str_split') ? mb_str_split($r, 1) : str_split($r, 1);
324+
}
325325
$this->barcode_array['code'] = $code;
326326
break;
327327
}

0 commit comments

Comments
 (0)