dou8mwz5079 2018-01-23 14:54
浏览 42
已采纳

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

I am using the Twig template engine and I have just upgraded my PHP version to 7.1.

I now get the following warning when rendering any page:

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" />

This looks to be referring to the following line in the Twig/Environment.php file

eval('?>'.$content);

Here's the content of the $content variable:

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");
    }
}

I'm just not too sure where the non-numeric value is. Any ideas please?

I'm not sure it's relevant but I'm using Codeigniter 3...

  • 写回答

1条回答 默认 最新

  • drbhjey445647 2018-01-29 11:06
    关注

    OK, so it seems in this case I just needed to trawl through my twig file and find the non-numeric value and give it a default of 0 if it's not set.

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

    Becomes

    <input type="hidden" name="vals" value="{{ (my_var|default(0) * 'now'|date('Y') }}" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000