Php 致命错误:未捕获类型错误:不支持的操作数类型:字符串+;整数

Php 致命错误:未捕获类型错误:不支持的操作数类型:字符串+;整数,php,Php,这是我的错误标题: 致命错误:未捕获类型错误:不支持的操作数类型:C:\xamppp\htdocs\file\thefile\config.php中的字符串+int:105堆栈跟踪:#0 C:\xamppp\htdocs\file\thefile\thefile\category.php(84):在第105行的C:\xamppp\htdocs\file\thefile\thefile\thefile\thefile\category.php中抛出alphaID('f',true)#1{main}

这是我的错误标题:

致命错误:未捕获类型错误:不支持的操作数类型:C:\xamppp\htdocs\file\thefile\config.php中的字符串+int:105堆栈跟踪:#0 C:\xamppp\htdocs\file\thefile\thefile\category.php(84):在第105行的C:\xamppp\htdocs\file\thefile\thefile\thefile\thefile\category.php中抛出alphaID('f',true)#1{main}

第105行的错误:

{$out = $out + strpos($index, substr($in, $t, 1)) * $bcp;}
这是代码:

<?php

//fungsi encrypt id
function alphaID($in, $to_num = false, $pad_up = false, $pass_key = null)
{
  $out   =   '';
  $index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $base  = strlen($index);

  if ($pass_key !== null) {

    for ($n = 0; $n < strlen($index); $n++) {
      $i[] = substr($index, $n, 1);
    }

    $pass_hash = hash('sha256',$pass_key);
    $pass_hash = (strlen($pass_hash) < strlen($index) ? hash('sha512', $pass_key) : $pass_hash);

    for ($n = 0; $n < strlen($index); $n++) {
      $p[] =  substr($pass_hash, $n, 1);
    }

    array_multisort($p, SORT_DESC, $i);
    $index = implode($i);
  }

  if ($to_num) {
    $len = strlen($in) - 1;

    for ($t = $len; $t >= 0; $t--) {
      $bcp = bcpow($base, $len - $t);
      $out = $out + strpos($index, substr($in, $t, 1)) * $bcp;
    }

    if (is_numeric($pad_up)) {
      $pad_up--;

      if ($pad_up > 0) {
        $out -= pow($base, $pad_up);
      }
    }
  } else {
    if (is_numeric($pad_up)) {
      $pad_up--;

      if ($pad_up > 0) {
        $in += pow($base, $pad_up);
      }
    }

    for ($t = ($in != 0 ? floor(log($in, $base)) : 0); $t >= 0; $t--) {
      $bcp = bcpow($base, $t);
      $a   = floor($in / $bcp) % $base;
      $out = $out . substr($index, $a, 1);
      $in  = $in - ($a * $bcp);
    }
  }

  return $out;
}
?>

您提供的错误仅在PHP8上发生,这是因为您试图将字符串添加到整数中。在以前的版本中,错误消息通常是“遇到一个非数字值”,这在某些情况下使问题更加清楚

您的问题将通过将
$out=''
更改为
$out=null
来解决,这对输出没有不利影响

  • 在PHPV5.6中,您将不会收到任何错误(代码工作正常)
  • 在PHPV7中,您将收到“遇到非数值”的警告
  • 在PHPV8中,您会收到一个致命错误,即“未捕获的TypeError:不支持的操作数类型:string+int”

您试图将字符串添加到整数中。检查您的类型该表达式中的
+
应该是
?这是一个计算,应该是
((int)$out+(int)strpos($index,substr($in,$t,1)))*$bcp
天哪,非常感谢您的帮助。它修好了。你分享了我还不知道的新信息。非常感谢。:)没问题,请给答案打勾并投上一票,这样我就可以得到一点帮助奖金:)祝你好运!绝对是修复,但犯错误并不羞耻。尝试在PHP8上安装woocommerce。