php – 编译错误:不能对表达式的结果使用isset()

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 编译错误:不能对表达式的结果使用isset()脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在从Sf2.0.x迁移到SF2.7的应用程序中收到此错误
[1] Symfony\component\Debug\Exception\FatalErrorException: Compile Error: Cannot use isset() on the result of an exPression (you can use "null !== exPRession" instead)
    at n/a
        in /VAR/www/htML/reptooln_admin/app/cache/dev/twig/68/7f/63589dd3687cb849dd68e6b6c10aa99eda1d82f95a5f3ac52a864d200499.PHP line 39

我不知道什么是失败或如何解决这个问题所以我需要一些建议.这是报告Stacktrace的缓存文件中的行:

if ((((empty((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context,"form_action"))) == true) || (isnull((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context,"form_action"))) == true)) || (isset((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context,"form_action"))) == false))) {
                echo " ";
                $context["form_action"] = "";
                echo " ";

我有这个TwigExtension:

class PDOneTwigExtension extends \Twig_Extension
{
    public function getfilters()
    {
        return array(
            'var_dump'   => new \Twig_Filter_Function('var_dump'),'empty' => new \Twig_Filter_Function('empty',array($this,'is_empty')),'isset' => new \Twig_Filter_Function('isset','is_set')),'isnull' => new \Twig_Filter_Function('isnull','is_null')),'ucFirst' => new \Twig_Filter_Function('uCFirst','uc_first')),'ucwords' => new \Twig_Filter_Function('ucwords','uc_words')),'count' => new \Twig_Filter_Function('count','co_unt')),'sizeof' => new \Twig_Filter_Function('sizeof','size_of')),'concat' => new \Twig_Filter_Function('concat','concat')),'in_array' => new \Twig_Filter_Function('in_array','inarray')),'array' => new \Twig_Filter_Function('array','array_')),'add_to_array' => new \Twig_Filter_Function('add_to_array','add_to_array')),'replace' => new \Twig_Filter_Function('replace','replace')),'htmlentITydecode' => new \Twig_Filter_Function('htmlentitydecode','htmlentitydecode'))
        );
    }

    public function is_empty($sentence)
    {
        return empty($sentence) ? true : false;
    }

    // rest of methods goes here

    public function getName()
    {
        return 'pdone_twig_extension';
    }
}

我在模板上使用如下:

{% if form_action|empty == true or form_action|isnull == true or form_action|isset == false %} {% set form_action = '' %} {% endif %}

问题出在哪里?有什么建议?

documentation开始

您没有直接将变量传递给isset().因此,您需要首先计算该值,将其分配给变量,然后将其传递给isset().

例如,您目前正在做的事情如下:

if(isset($something === false)) { } // throws a parse error,because $something === false is not a variable

你需要做的是:

$something = false;
if(isset($something)) { ... }

脚本宝典总结

以上是脚本宝典为你收集整理的php – 编译错误:不能对表达式的结果使用isset()全部内容,希望文章能够帮你解决php – 编译错误:不能对表达式的结果使用isset()所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。