编译错误:无法在表达式的结果上使用isset() [英] Compile Error: Cannot use isset() on the result of an expression

查看:116
本文介绍了编译错误:无法在表达式的结果上使用isset()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从SF2.0.x迁移到SF2.7的应用程序中遇到此错误:

I'm getting this error in a app I am migrating from SF2.0.x to 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的行:

I don't know what is failing or how to fix this so I need some advise. This is the line at cache file where the Stacktrace is reported:

    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:

What I have this 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', array($this, 'is_set')),
            'isnull' => new \Twig_Filter_Function('isnull', array($this, 'is_null')),
            'ucfirst' => new \Twig_Filter_Function('ucfirst', array($this, 'uc_first')),
            'ucwords' => new \Twig_Filter_Function('ucwords', array($this, 'uc_words')),
            'count' => new \Twig_Filter_Function('count', array($this, 'co_unt')),
            'sizeof' => new \Twig_Filter_Function('sizeof', array($this, 'size_of')),
            'concat' => new \Twig_Filter_Function('concat', array($this, 'concat')),
            'in_array' => new \Twig_Filter_Function('in_array', array($this, 'inarray')),
            'array' => new \Twig_Filter_Function('array', array($this, 'array_')),
            'add_to_array' => new \Twig_Filter_Function('add_to_array', array($this, 'add_to_array')),
            'replace' => new \Twig_Filter_Function('replace', array($this, 'replace')),
            'htmlentitydecode' => new \Twig_Filter_Function('htmlentitydecode', array($this, 'htmlentitydecode'))
        );
    }

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

    // rest of methods goes here

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

我正在使用at模板,如下所示:

And I'm using at template as follow:

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

这里的问题可能在哪里?有什么建议吗?

Where could be the issue here? Any advice?

推荐答案

来自文档 a>:

isset()仅适用于变量,因为传递其他任何内容都会导致解析错误.

isset() only works with variables as passing anything else will result in a parse error.

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

You're not directly passing a variable to isset(). So you need to calculate the value first, assign it to a variable, and then pass that to isset().

例如,您目前正在做的事情是这样的:

For example, what you're doing at the moment is something like:

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

您需要做的是:

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

这篇关于编译错误:无法在表达式的结果上使用isset()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆