Skip to content

Commit

Permalink
Fix PHP8.2 str_split function returns empty arrays for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Feb 13, 2023
1 parent 2fb1c01 commit ae4f2e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions include/barcodes/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ public function __construct($code, $eclevel = 'L') {
$barcode_array['bcode'] = array();
foreach ($qrTab as $line) {
$arrAdd = array();
foreach (str_split($line) as $char) {
$chars = function_exists('mb_str_split') ? mb_str_split($line) : str_split($line);
foreach ($chars as $char) {
$arrAdd[] = ($char=='1')?1:0;
}
$barcode_array['bcode'][] = $arrAdd;
Expand Down Expand Up @@ -1307,7 +1308,8 @@ protected function eatNum() {
return $this->eatAn();
}
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, $data);
return $run;
}

Expand Down Expand Up @@ -1346,7 +1348,8 @@ protected function eatAn() {
return $this->eat8();
}
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, $data);
return $run;
}

Expand All @@ -1359,7 +1362,8 @@ protected function eatKanji() {
while($this->identifyMode($p) == QR_MODE_KJ) {
$p += 2;
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, $data);
$run = $p;
return $run;
}
Expand Down Expand Up @@ -1409,7 +1413,8 @@ protected function eat8() {
}
}
$run = $p;
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, $data);
return $run;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tcpdf_fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
} else {
$chars = str_split($str);
$chars = function_exists('mb_str_split') ? mb_str_split($str) : str_split($str);
$carr = array_map('ord', $chars);
}
if (is_array($currentfont['subsetchars']) && is_array($carr)) {
Expand Down
4 changes: 2 additions & 2 deletions tcpdf_barcodes_1d.php
Original file line number Diff line number Diff line change
Expand Up @@ -2179,8 +2179,8 @@ protected function barcode_imb_pre($code) {
if (!preg_match('/^[fadtFADT]{65}$/', $code) == 1) {
return false;
}
$characters = str_split(strtolower($code), 1);
// build bars
$characters = function_exists('mb_str_split') ? mb_str_split(strtolower($code), 1) : str_split(strtolower($code), 1);
// build bars
$k = 0;
$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
for ($i = 0; $i < 65; ++$i) {
Expand Down
4 changes: 2 additions & 2 deletions tcpdf_barcodes_2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ public function setBarcode($code, $type) {
$this->barcode_array['num_cols'] = strlen($rows[0]);
$this->barcode_array['bcode'] = array();
foreach ($rows as $r) {
$this->barcode_array['bcode'][] = str_split($r, 1);
}
$this->barcode_array['bcode'][] = function_exists('mb_str_split') ? mb_str_split($r, 1) : str_split($r, 1);
}
$this->barcode_array['code'] = $code;
break;
}
Expand Down

0 comments on commit ae4f2e8

Please sign in to comment.