PHP 7.1'遇到非数字值'与Twig 1.35

时间:2018-01-23 14:54:22

标签: php codeigniter symfony twig php-7.1

我正在使用Twig模板引擎,我刚刚将PHP版本升级到7.1。

我现在在渲染任何页面时收到以下警告:

A PHP Error was encountered
Severity: Warning

Message: A non-numeric value encountered

Filename: Twig/Environment.php(469) : eval()'d code

Line Number: 91

Backtrace:

File: /var/www/html/application/third_party/Twig/lib/Twig/Environment.php(471) : eval()'d code
Line: 91
Function: _error_handler

File: /var/ww...

...

...html/index.php
Line: 320
Function: require_once

0" />

这看起来是指Twig / Environment.php文件中的以下行

eval('?>'.$content);

这里是$ content变量的内容:

parent = $this->loadTemplate("base.twig", "twig/index.twig", 1);
        $this->blocks = array(
            'content' => array($this, 'block_content'),
        );
    }

    protected function doGetParent(array $context)
    {
        return "base.twig";
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        $this->parent->display($context, array_merge($this->blocks, $blocks));
    }

    // line 3
    public function block_content($context, array $blocks = array())
    {
        // line 4
        echo "        
";
    }

    public function getTemplateName()
    {
        return "twig/index.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  31 => 4,  28 => 3,  11 => 1,);
    }

    /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
    public function getSource()
    {
        @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);

        return $this->getSourceContext()->getCode();
    }

    public function getSourceContext()
    {
        return new Twig_Source("", "twig/index.twig", "/var/www/html/application/views/twig/index.twig");
    }
}

我不太确定非数字值在哪里。有什么想法吗?

我不确定它是否相关但我使用的是Codeigniter 3 ...

1 个答案:

答案 0 :(得分:0)

好的,所以在这种情况下,我只需要浏览我的twig文件并找到非数字值,如果没有设置,则默认值为0.

<input type="hidden" name="vals" value="{{ (my_var * 'now'|date('Y') }}" />

变为

<input type="hidden" name="vals" value="{{ (my_var|default(0) * 'now'|date('Y') }}" />