折雨的天空

博客介绍:本博客当前共有文章【962】篇,总阅读量【5,050,146】次,第一篇博客发表于【2011年04月06日 10时34分】,距今已【4912】天,感谢您的使用!

您的位置:折雨的天空 >php开发> 一个诡异的Thinkphp8的验证场景的错误,报错内存溢出Allowed memory size of

一个诡异的Thinkphp8的验证场景的错误,报错内存溢出Allowed memory size of

代码:


public function sceneDelete()
    {
        return $this->only(['id'])->append('id', 'checkAbleDelete');
    }

这是一个删除场景的验证,id自带验证规则如下:



protected $rule = [
        'id' => 'require|checkCategory',
        'name'  =>  'require|unique:'.ArticleCategory::class,
        'status' => 'require|in:0,1',
    ];

验证方法:




protected  function checkCategory($value)
    {
        $category = ArticleCategory::findOrEmpty($value);
        if ($category->isEmpty()) {
            return '文章分类不存在';
        }
        return true;
    }

另外一个方法:



protected function checkAbleDelete($value)
    {
        $hasArticle = ArticleInfo::where(['category_id' => $value])->findOrEmpty();
        if (!$hasArticle->isEmpty()) {
            return '该分类已被文章使用,暂不可删除';
        }
        unset($hasArticle);
        $hasSon = ArticleCategory::where(['parent_id' => $value])->findOrEmpty();
        if (!$hasSon->isEmpty()) {
            return '该分类存在子分类,暂不可删除';
        }
        unset($hasSon);
        $dept = ArticleCategory::findOrEmpty($value);
        if ($dept['parent_id'] == 0) {
            return '顶级分类不可删除';
        }
    //罪魁祸首
        return true;
    }

问题就是,验证的时候try,catch会走catch,但是获取不到验证的错误信息,getTraceAsString可以获取到Allowed memory size of错误。


开了调试模式,看了apache日志,没有什么错误,始终不得其解。


最后原因,就是上面代码中的return true的那句话,由于验证方法不规范,验证通过没有返回true,导致内存移除。

排查的时候我把checkAbleDelete的内容全部注释完,都会报内存移除,切记要返回值。

------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------

转载请注明本文标题和链接:《一个诡异的Thinkphp8的验证场景的错误,报错内存溢出Allowed memory size of

奖励一下

取消

分享不易,烦请有多多打赏,如您也困难,点击右边关闭即可!

扫码支持
扫码打赏,5元,10元,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

-秒后自动关闭,如已打赏,或者不愿打赏,请点击右上角关闭图标。

发表评论

路人甲 表情
看不清楚?点图切换