PHP 7.1 'A non-numeric value encountered' 与树枝 1.35
PHP 7.1 'A non-numeric value encountered' with Twig 1.35
我正在使用 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...
好的,所以在这种情况下,我似乎只需要浏览我的 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') }}" />
我正在使用 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...
好的,所以在这种情况下,我似乎只需要浏览我的 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') }}" />