php 8.1 上的 PHPIDS 已弃用错误 [重复]

2024-05-22

我在 PHP 8.1 服务器上遇到 PHPIDS 问题。

这里的错误:

PHP Deprecated: Return type of IDS\Report::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phpids\ib\IDS\Report.php on line 205

PHP Deprecated: Return type of IDS\Report::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phpids\lib\IDS\Report.php on line 218

我知道弃用错误并没有那么糟糕,但我希望一切都完美。 我在谷歌中搜索了一些东西,但没有找到解决方案。 希望你能找到问题所在。

我使用来自 Github 的实际 PHPIDS 版本(https://github.com/PHPIDS/PHPIDS https://github.com/PHPIDS/PHPIDS) 我知道这个版本不是最新的,但我没有找到更新的版本。

谢谢你的帮助

这里是脚本 Report.php

<?php
/**
 * PHPIDS
 *
 * Requirements: PHP5, SimpleXML
 *
 * Copyright (c) 2008 PHPIDS group (https://phpids.org)
 *
 * PHPIDS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License, or
 * (at your option) any later version.
 *
 * PHPIDS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5.1.6+
 *
 * @category Security
 * @package  PHPIDS
 * @author   Mario Heiderich <[email protected] /cdn-cgi/l/email-protection>
 * @author   Christian Matthies <[email protected] /cdn-cgi/l/email-protection>
 * @author   Lars Strojny <[email protected] /cdn-cgi/l/email-protection>
 * @license  http://www.gnu.org/licenses/lgpl.html LGPL
 * @link     http://php-ids.org/
 */
namespace IDS;

/**
 * PHPIDS report object
 *
 * The report objects collects a number of events and thereby presents the
 * detected results. It provides a convenient API to work with the results.
 *
 * Note that this class implements Countable, IteratorAggregate and
 * a __toString() method
 *
 * @category  Security
 * @package   PHPIDS
 * @author    Christian Matthies <[email protected] /cdn-cgi/l/email-protection>
 * @author    Mario Heiderich <[email protected] /cdn-cgi/l/email-protection>
 * @author    Lars Strojny <[email protected] /cdn-cgi/l/email-protection>
 * @copyright 2007-2009 The PHPIDS Group
 * @license   http://www.gnu.org/licenses/lgpl.html LGPL
 * @link      http://php-ids.org/
 */
class Report implements \Countable, \IteratorAggregate
{
    /**
     * Event container
     *
     * @var Event[]|array
     */
    protected $events = array();

    /**
     * List of affected tags
     *
     * This list of tags is collected from the collected event objects on
     * demand when IDS_Report->getTags() is called
     *
     * @var string[]|array
     */
    protected $tags = array();

    /**
     * Impact level
     *
     * The impact level is calculated on demand by adding the results of the
     * event objects on IDS\Report->getImpact()
     *
     * @var integer
     */
    protected $impact = 0;

    /**
     * Centrifuge data
     *
     * This variable - initiated as an empty array - carries all information
     * about the centrifuge data if available
     *
     * @var array
     */
    protected $centrifuge = array();

    /**
     * Constructor
     *
     * @param array $events the events the report should include
     *
     * @return Report
     */
    public function __construct(array $events = null)
    {
        foreach ((array) $events as $event) {
            $this->addEvent($event);
        }
    }

    /**
     * Adds an IDS_Event object to the report
     *
     * @param Event $event IDS_Event
     *
     * @return self $this
     */
    public function addEvent(Event $event)
    {
        $this->clear();
        $this->events[$event->getName()] = $event;

        return $this;
    }

    /**
     * Get event by name
     *
     * In most cases an event is identified by the key of the variable that
     * contained maliciously appearing content
     *
     * @param string|integer $name the event name
     *
     * @throws \InvalidArgumentException if argument is invalid
     * @return Event|null                    IDS_Event object or false if the event does not exist
     */
    public function getEvent($name)
    {
        if (!is_scalar($name)) {
            throw new \InvalidArgumentException('Invalid argument type given');
        }

        return $this->hasEvent($name) ? $this->events[$name] : null;
    }

    /**
     * Returns list of affected tags
     *
     * @return string[]|array
     */
    public function getTags()
    {
        if (!$this->tags) {
            $this->tags = array();

            foreach ($this->events as $event) {
                $this->tags = array_merge($this->tags, $event->getTags());
            }

            $this->tags = array_values(array_unique($this->tags));
        }

        return $this->tags;
    }

    /**
     * Returns total impact
     *
     * Each stored IDS_Event object and its IDS_Filter sub-object are called
     * to calculate the overall impact level of this request
     *
     * @return integer
     */
    public function getImpact()
    {
        if (!$this->impact) {
            $this->impact = 0;
            foreach ($this->events as $event) {
                $this->impact += $event->getImpact();
            }
        }

        return $this->impact;
    }

    /**
     * Checks if a specific event with given name exists
     *
     * @param string|integer $name the event name
     *
     * @throws \InvalidArgumentException if argument is illegal
     * @return boolean
     */
    public function hasEvent($name)
    {
        if (!is_scalar($name)) {
            throw new \InvalidArgumentException('Invalid argument given');
        }

        return isset($this->events[$name]);
    }

    /**
     * Returns total amount of events
     *
     * @return integer
     */


    
    public function count()
    {
        return @count($this->events);
    }
    /**
     * Return iterator object
     *
     * In order to provide the possibility to directly iterate over the
     * IDS_Event object the IteratorAggregate is implemented. One can easily
     * use foreach() to iterate through all stored IDS_Event objects.
     *
     * @return \Iterator the event collection
     */
    public function getIterator()
    {
        return new \ArrayIterator($this->events);
    }

    /**
     * Checks if any events are registered
     *
     * @return boolean
     */
    public function isEmpty()
    {
        return empty($this->events);
    }

    /**
     * Clears calculated/collected values
     *
     * @return void
     */
    protected function clear()
    {
        $this->impact = 0;
        $this->tags   = array();
    }

    /**
     * This method returns the centrifuge property or null if not
     * filled with data
     *
     * @return array
     */
    public function getCentrifuge()
    {
        return $this->centrifuge;
    }

    /**
     * This method sets the centrifuge property
     *
     * @param array $centrifuge the centrifuge data
     *
     * @throws \InvalidArgumentException if argument is illegal
     * @return void
     */
    public function setCentrifuge(array $centrifuge = array())
    {
        if (!$centrifuge) {
            throw new \InvalidArgumentException('Empty centrifuge given');
        }
        $this->centrifuge = $centrifuge;
    }

    /**
     * Directly outputs all available information
     *
     * @return string
     */
    public function __toString()
    {
        $output = '';
        if (!$this->isEmpty()) {
            $output .= vsprintf(
                "Total impact: %d<br/>\nAffected tags: %s<br/>\n",
                array(
                    $this->getImpact(),
                    implode(', ', $this->getTags())
                )
            );

            foreach ($this->events as $event) {
                $output .= vsprintf(
                    "<br/>\nVariable: %s | Value: %s<br/>\nImpact: %d | Tags: %s<br/>\n",
                    array(
                        htmlspecialchars($event->getName()),
                        htmlspecialchars($event->getValue()),
                        $event->getImpact(),
                        implode(', ', $event->getTags())
                    )
                );

                foreach ($event as $filter) {
                    $output .= vsprintf(
                        "Description: %s | Tags: %s | ID %s<br/>\n",
                        array(
                            $filter->getDescription(),
                            implode(', ', $filter->getTags()),
                            $filter->getId()
                        )
                    );
                }
            }

            $output .= '<br/>';

            if ($centrifuge = $this->getCentrifuge()) {
                $output .= vsprintf(
                    "Centrifuge detection data<br/> Threshold: %s<br/> Ratio: %s",
                    array(
                        isset($centrifuge['threshold']) && $centrifuge['threshold'] ? $centrifuge['threshold'] : '---',
                        isset($centrifuge['ratio']) && $centrifuge['ratio'] ? $centrifuge['ratio'] : '---'
                    )
                );
                if (isset($centrifuge['converted'])) {
                    $output .= '<br/>  Converted: ' . $centrifuge['converted'];
                }
                $output .= "<br/><br/>\n";
            }
        }

        return $output;
    }
}

从 PHP 8.1 开始,您必须修复函数的返回类型count() and getIterator()与接口相匹配。

  • public count(): int (see 可数 https://www.php.net/Countable)
  • public getIterator(): Traversable (see 迭代器聚合 https://www.php.net/IteratorAggregate)
class Report implements \Countable, \IteratorAggregate
{
    protected array $events;

    public function count(): int
    {
        return count($this->events);
    }

    public function getIterator(): \Traversable
    {
        return new \ArrayIterator($this->events);
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

php 8.1 上的 PHPIDS 已弃用错误 [重复] 的相关文章

  • 变量前面的@是什么意思? [复制]

    这个问题在这里已经有答案了 可能的重复 参考 这个符号在 PHP 中意味着什么 https stackoverflow com questions 3737139 reference what does this symbol mean i
  • 如何在 CodeIgniter 中取消链接(删除)图像

    我试着unlinkCodeIgniter 中的图像 但是unlink函数显示 注意未定义索引 userfile 这是我的代码
  • 如何按日期对包含通过合并 get_posts 结果创建的 WP po​​st 对象的数组进行排序?

    我想通过合并 2 个单独的帖子的结果来创建单个帖子数组get posts查询 并按发布日期对数组进行排序 在我下面的代码中 get posts 为 args b and args a已合并为一个数组 但它们是分开的 的 9 个标题 args
  • $.load 内的表单未正确发布

    这就是我得到的 基本上单击一个按钮并执行以下代码 Readthis MonsterRequest php id Mon TestVar TestVar replace s g Readthis Readthis htmlencode Tes
  • 只获取倒数第二条记录 - mysql-query

    我有一个如下表记录 my table id rating description 1 0 0 bed 2 1 0 good 3 0 0 bed 4 1 0 good 5 0 0 bed 6 0 0 bed 7 0 0 bed 现在我通过评级
  • 不带 GROUP BY 的聚合查询

    这个查询似乎在我的旧机器上完美运行 但是 在我的 MySQL 5 7 14 和 PHP 5 6 25 的新机器上 它会抛出错误 致命错误 未捕获异常 PDOException 并带有消息 SQLSTATE 42000 语法错误或访问冲突 1
  • 如果遵循 REST 架构,如何访问 codeigniter 中的 URL 参数?

    以下是可用于访问资源的基于 REST 的有效 URL 使用codeigniter 如何访问下面传递的参数1 我在教程中看到了上述内容并设置了我的代码 然而显然 id this gt input gt get id 不起作用 Using th
  • PHP-将字符串转换为unicode

    我在做这个工作 source mb convert encoding test unicode utf 8 source unpack C source var dump source return array size 8 1 gt in
  • 在 PHP 中重新定义常量

    是否可以在 php 中重新定义由define功能 我有一个包含多个常量的类 其中包含用户数据 我正在尝试为多个用户使用该类 define ALLEGRO ID id define ALLEGRO LOGIN login define ALL
  • php - 未知:第 0 行需要打开失败。laravel 5.6

    我刚刚安装了 laracast flash 并通过 Composer 更新了 nesbot carbon 下载碳时命令发疯了 Cmd界面显示了一会界面上散落的文字和方框 下载完成 做过php artisan serve at localho
  • PHP 数组到 JavaScript 数组

    假设我在 php 中有这个数组 cities array Caracas gt array air gt array 4 3 5 Working Days Saturday sea gt array 18 3 5 Days Wednesda
  • PHP - 当 false 时获取 bool 来回显 false

    以下代码不会打印出任何内容 bool val bool false echo bool val 但下面的代码打印1 bool val bool true echo bool val 有没有更好的打印方法0 or false when boo
  • 多维数组内的移动

    我有一个用表格显示的数组 如何使用用户输入进行移动 目前 0 被分配给每个数组 但我计划为该数组分配其他值 我的问题是 如何使用用户输入在数组内向上 向下 向右 向左移动和对角移动 Array 0 gt Array 0 gt 0 1 gt
  • 支持通过 OAuth 进行 Facebook/Twitter 身份验证的 CAS 服务器

    我正在寻找一个支持 Facebook Twitter 通过 OAuth 进行单点登录身份验证的 CAS 服务器 我检查过 JASIG CAS 服务器 但它看起来不支持它们 我的 java web 应用程序基于 Spring Security
  • Jquery UI 日期选择器 设置默认日期

    我使用 jQuery UI 作为日期选择器 我想在字段中显示当前日期作为默认值 以下是我的代码 请帮助 From Date
  • 通过 jQuery 从输入类型=“文件”多个中删除文件

    我在使用 PHP 和 jQuery 上传文件时遇到问题 表单可以一次上传多个图像 这些图像可以在滑块中预览 表单还包含两个字段标题和描述 滑块通过 jQuery 工作 当用户通过单击选择文件来选择多个图像时
  • 纠正装饰器模式的一个大缺点

    不久前 我在重构一些游戏战斗代码时决定尝试装饰器模式 战斗者可以拥有各种被动能力 也可能是不同类型的生物 我认为装饰器可以让我在运行时以各种组合添加行为 因此我不需要数百个子类 我几乎已经完成了 15 个左右的被动能力装饰器 在测试中我发现
  • 让登录更安全

    我已使用此代码进行管理员登录 仅当用户输入正确的用户名和密码时才应打开loginhome php 但后来我意识到这根本不安全 任何人都可以直接访问 mywebsite loginhome php 而无需登录 注销后 可以使用后退按钮打开 l
  • Zend Framework 生成唯一的字符串

    我想生成一个唯一的 4 6 个字符长的字母数字字符串 以便与每个记录 用户 一起保存在数据库中 db 字段具有唯一索引 因此尝试保存预先存在的字符串会生成错误 现在我正在生成一个随机字符串并使用 try catch 因此在添加新记录时如果抛
  • openssl_pkey_get_details($res) 不返回公共指数

    我在用着这个例子 https stackoverflow com a 12575951 2016196使用 php 生成的密钥进行 javascript 加密openssl图书馆 但是 details openssl pkey get de

随机推荐

  • golang中通道缓冲容量0和1的区别

    我已将通道缓冲区大小设置为零 例如var intChannelZero make chan int 当从intChannelZero将被阻止 直到intChannelZero有价值 另外 我将通道缓冲区大小设置为 1 例如var intCh
  • Android smoothScrollTo 不调用 onScrollStateChanged

    我在用smoothScrollBy 滚动到 a 中的特定位置ListView 我希望在以下情况时得到通知ListView完成滚动以将其与当前集成onScrollStateChanged 当用户用手指滚动时触发的事件 目前我正在使用Timer
  • DOM 中不再存在缓存元素

    就像在类似的问题中一样 我使用appium java 尝试选择元素 在移动应用程序中 我要转到页面 之后有许多元素 android widget ImageView 0 我需要选择 6 个 例如 这样的元素并执行其他步骤 Byt 只能选择一
  • 运行pyspark时没有这样的文件或目录错误

    我安装了 Spark 但是当我运行时pyspark在终端上 我得到 usr local Cellar apache spark 2 4 5 1 libexec bin pyspark line 24 Users miguel spark 2
  • 如何恢复丢失的aws服务器实例的私钥?

    我丢失了 AWS 实例的私钥 我在控制台面板中搜索了该选项 恐怕你可能不走运 当您启动实例时 您应该指定密钥的名称 您计划用于连接到实例的对 如果你不指定 启动实例时现有密钥对的名称 您 将无法连接到实例 当您连接到 例如 您必须指定与密钥
  • Mongodb 以不区分大小写的方式排序

    我在 Nodejs express 中以 mongodb 作为数据库的一个项目中非常努力地构建 当我使用 sort 获取所有数据时 它以错误的方式返回数据 那么有没有办法按照我的预期得到正确的格式 如下所示 如果我们在数据库中有三个记录 i
  • <%: 和 <%= 与嵌入代码(表达式)块相同吗

    刚开始使用 MVC 2 我注意到他们在入门模板中使用 我确信在 MVC 1 中它是 它们是一样的吗 如果是这样 为什么从等号改为冒号 冒号语法意味着您将自动进行 html 编码 http haacked com archive 2009 0
  • 在keras自定义损失中使用层输出

    我正在 Keras 中开发自定义损失函数 我需要第一层输出 我怎样才能取回它 def custom loss y true y pred cross K mean K binary crossentropy y true y pred ax
  • jQuery Mobile 数据过滤器,以防没有结果

    我目前正在探索 jQuery Mobile 以开发带有订单跟踪信息的移动版仪表板 计划是使用一个包含所有订单的简单无序列表 人们可以单击他们想了解更多信息的链接 由于此列表可能会变得相当大 因此拥有过滤功能非常好 使用 jQuery Mob
  • startDrag 方法 已弃用且无法编译程序

    startDrag android content ClipData android view View DragShadowBuilder java lang Object int 已弃用 如何解决这个问题而又不失去对旧版本的兼容性 还有
  • 如何让 IPython 按类别组织制表符补全的可能性?

    当一个对象有数百个方法时 制表符补全很难使用 通常 有趣的方法是由被检查对象的类而不是其基类定义或重写的方法 如何让 IPython 对其制表符完成可能性进行分组 以便首先检查对象的类中定义的方法和属性 然后是基类中的方法和属性 看起来像是
  • Rails“where”方法通过子属性查找父级

    我有一个 Rails 应用程序 我试图根据子类的日期创建父类的列表 现在我有 orders Order where order reminders date lt 1 month from now 但我收到一个错误 没有这样的列 order
  • 恢复默认的CSS属性

    我正在编写一个可在多个网站上使用的组件 每个网站都有自己的样式表 并且以不同的方式显示某些内容 我的所有 html 都包含在一个带有 id 的 div 中 div div 然而 我的组件是在所有网站上看起来一致 这很好 因为我将样式应用于组
  • 什么是 Kubernetes 清单?

    我在网上搜索过 大多数链接似乎都提到了清单 但没有实际解释它们是什么 什么是清单 它基本上是 Kubernetes API 对象描述 配置文件可以包含其中的一个或多个 即 Deployment ConfigMap Secret Daemon
  • C++ Primer 5th Edition 错误 bool 值没有指定最小大小?

    bool 的最小大小不应该是 1 个字节吗 这有点学术性的东西 尽管它们会转换为数字 并且 与其他所有事物一样 它们最终将基本上由计算机内存中的数字表示 但布尔值不是数字 你的bool可以取值true 或值false 即使您确实需要至少 1
  • 检测浏览器是否支持 contentEditable?

    There s 这个问题 https stackoverflow com questions 3497942 browser detect contenteditable features 但发布的解决方案是浏览器嗅探 我试图避免这种情况
  • 为什么Python安装程序不断弹出?

    每当我尝试运行 Python 文件时 都会自动弹出此窗口 虽然 我可以关闭它 但有时它会连续打开 7 10 个窗口 这令人恼火 谁能告诉我为什么会发生这种情况 None
  • git-lfs 中的多个文件版本

    我正在尝试估计 GitHub 上我的项目的存储要求 并对 git lfs 如何存储多个版本的文件有一些疑问 git lfs 是否存储多个版本的文件 如果是这样 对文件的每次更改都会导致复制整个文件 还是仅存储差异 所有版本都会计入 gith
  • 实现具有更广泛方法签名的接口

    在Go中 是否有一种方法可以使用方法来实现接口 其中实现中相应方法的返回类型 比 预期返回类型 更宽 这很难解释 所以这里有一个例子 在 Go Playground 中运行以下示例代码时出现此错误 prog go 36 14 cannot
  • php 8.1 上的 PHPIDS 已弃用错误 [重复]

    这个问题在这里已经有答案了 我在 PHP 8 1 服务器上遇到 PHPIDS 问题 这里的错误 PHP Deprecated Return type of IDS Report count should either be compatib