【问题标题】:PHP 7.1 'A non-numeric value encountered' with Twig 1.35Twig 1.35 的 PHP 7.1 '遇到的非数字值'
【发布时间】:2018-07-02 10:37:58
【问题描述】:

我正在使用 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...

【问题讨论】:

    标签: php codeigniter symfony twig php-7.1


    【解决方案1】:

    好的,所以在这种情况下,我似乎只需要浏览我的 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') }}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多