猿问

Symfony 4:Unsezialise(),["allowed_classes" =>

我正在使用 Synfony 4 开发一个网站并创建了一个管理员登录。我使用了序列化和反序列化。


  /**

     * @inheritDoc

     */

    public function serialize()

    {

        // TODO: Implement serialize() method.

        return serialize([

            $this->id,

            $this->username,

            $this->password

        ]);

    }


    /**

     * @inheritDoc

     */

    public function unserialize($serialized)

    {

        // TODO: Implement unserialize() method.

        list(

            $this->id,

            $this->username,

            $this->password

            ) = $this->unserialize($serialized, ["allowed_classes" => false]);

    }

最后$this->unserialize($serialized, ["allowed_classes" => false]);不起作用并显示“方法调用提供了 2 个参数,但方法签名使用 1 个参数”作为 Intellij IDEA 中的错误。我不明白这意味着什么,也找不到任何关于它的信息。


我认为基本方法只是想要unserialize($serialized)或类似的东西,但是当我填写表格并发送它时,什么也没有发生。


牧羊人nacy
浏览 133回答 1
1回答

呼唤远方

我们不知道这些方法的上下文,但使用$this->unserialize(...),您正在调用当前函数 ( public function unserialize($serialized){...})您可能想要使用默认的 PHP 序列化程序。因此,您可能应该执行以下操作:public function unserialize($serialized){    list(        $this->id,        $this->username,        $this->password        ) = unserialize($serialized, ["allowed_classes" => false]);}如果“什么都没发生”,没有关于该问题的更多信息,我们将无法为您提供帮助!您是否尝试添加任何转储来检查发生了什么?
随时随地看视频慕课网APP
我要回答