【问题标题】:Fatal error: Uncaught TypeError: Unsupported operand types: string + int in致命错误:未捕获的类型错误:不支持的操作数类型:字符串 + int in
【发布时间】:2021-05-20 02:38:15
【问题描述】:

这是我的错误标题:

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

第 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;
}
?>

【问题讨论】:

  • 您正在尝试将字符串添加到整数。检查您的类型
  • 该表达式中的 + 是否应该是 .
  • 这是一个计算,应该是((int)$out + (int)strpos($index, substr($in, $t, 1))) * $bcp

标签: php php-8


【解决方案1】:

当我重定向到新页面时我也有同样的错误 所以我只在上一页上使用(int),我使用$_SERVER['QUERY_STRING'] 语句,就像在php 8.0 中的(int) $_SERVER['QUERY_STRING'] 我的问题已经解决了希望对你有帮助

【讨论】:

    【解决方案2】:

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

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

    • 在 PHP v5.6 中,您将不会收到任何错误(并且代码可以正常工作)
    • 在 PHP v7 中,您会收到“遇到非数字值”的警告通知
    • 在 PHP v8 中,您会收到“未捕获的 TypeError:不支持的操作数类型:字符串 + int”的致命错误通知

    【讨论】:

    • omg 非常感谢您的帮助。它修复了。你分享了我还不知道的新信息。太感谢了。 :)
    • 没问题,请给答案打勾并点个赞,这样我就可以得到一点帮助:)祝你好运!
    • 绝对是修复,但犯错误并不羞耻。尝试在 PHP8 上安装 woocommerce。
    • @PuspaIndahRamidawati 请将此答案标记为已接受,因为它是解决方案...
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2013-10-04
    • 2021-06-16
    • 2014-06-16
    相关资源
    最近更新 更多