PHP严格标准:只有变量才能通过引用传递
我从tmp templates_c文件夹中的文件中得到一个错误。错误日志中的错误如下所示:PHP严格标准:只有变量才能通过引用传递,php,Php,我从tmp templates_c文件夹中的文件中得到一个错误。错误日志中的错误如下所示: PHP Strict Standards: Only variables should be passed by reference in MYSITE/public_html/tmp/templates_c/%%62^625^625F77C9%%register.tpl.php on line 31 第31行的代码是: <?php $this->_block_content = ob_
PHP Strict Standards: Only variables should be passed by reference in MYSITE/public_html/tmp/templates_c/%%62^625^625F77C9%%register.tpl.php on line 31
第31行的代码是:
<?php
$this->_block_content = ob_get_contents();
ob_end_clean();
echo smarty_block_m3_validate_box($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat=false); } array_pop($this->_tag_stack);
?>
以下是smarty_block_m3_validate_box函数:
function smarty_block_m3_validate_box($params, $content, &$smarty, &$repeat)
{
$required_params = array();
$optional_params = array('form'=>'default'
,'message'=> 'There was a problem:'
,'class' => 'validation-box'
,'assign' => ''
);
// process parameters and bring into local namespace
foreach($required_params as $p)
{
if (!isset($params[$p])) {
$smarty->trigger_error("m3_validate_box: missing parameter: $p", E_USER_NOTICE);
return '';
}
$$p = $params[$p];
}
foreach($optional_params as $parameter => $default_value)
{
$$parameter = empty($params[$parameter]) ? $default_value : $params[$parameter];
}
if (!empty($content))
{
// closing {{m3_validate_box}} tag
if(!empty($_SESSION['SmartyValidate'][$form]['is_error']))
{
$output = "\n<div class='$class'>$message\n<ul>\n";
$output .= $content;
$output .= "\n</ul>\n</div>\n";
if(!empty($assign))
$smarty->assign($assign, $output);
else
{
echo $output;
}
}
}
}
<?php
$_block_repeat = false;
smarty_block_m3_validate_box($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat);
函数smarty_block_m3_validate_box($params,$content,&$smarty,&$repeat)
{
$required_params=array();
$optional_params=array('form'=>'default'
,'message'=>'出现问题:'
,“类”=>“验证框”
,“分配”=>“
);
//进程参数并将其引入本地命名空间
foreach($p所需参数)
{
如果(!isset($params[$p])){
$smarty->trigger_error(“m3_validate_box:缺少参数:$p”,E_用户通知);
返回“”;
}
$$p=$params[$p];
}
foreach($parameter=>$default\u值的可选参数)
{
$$parameter=空($params[$parameter])?$default_值:$params[$parameter];
}
如果(!空($content))
{
//正在关闭{m3\u validate\u box}}标记
如果(!empty($\u会话['SmartyValidate'][$form]['is\u error']))
{
$output=“\n$message\n\n”;
$output.=$content;
$output.=“\n
\n\n”;
如果(!空($assign))
$smarty->assign($assign,$output);
其他的
{
echo$输出;
}
}
}
}
我从其他开发人员那里继承了这段代码,但我不太了解smarty,因此很抱歉没有提供详细信息 问题在于代码的这一部分:
<?php
smarty_block_m3_validate_box($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat=false);
(参数3和4通过引用传递)
现在,您试图将$\u block\u repeat=false作为第三个参数传递,这将起作用,但会抛出一个E\u STRICT错误(如您所得到的)。解决方案是使用所需的值分配$\u block\u repeat
,并将其传递给函数:
function smarty_block_m3_validate_box($params, $content, &$smarty, &$repeat)
{
$required_params = array();
$optional_params = array('form'=>'default'
,'message'=> 'There was a problem:'
,'class' => 'validation-box'
,'assign' => ''
);
// process parameters and bring into local namespace
foreach($required_params as $p)
{
if (!isset($params[$p])) {
$smarty->trigger_error("m3_validate_box: missing parameter: $p", E_USER_NOTICE);
return '';
}
$$p = $params[$p];
}
foreach($optional_params as $parameter => $default_value)
{
$$parameter = empty($params[$parameter]) ? $default_value : $params[$parameter];
}
if (!empty($content))
{
// closing {{m3_validate_box}} tag
if(!empty($_SESSION['SmartyValidate'][$form]['is_error']))
{
$output = "\n<div class='$class'>$message\n<ul>\n";
$output .= $content;
$output .= "\n</ul>\n</div>\n";
if(!empty($assign))
$smarty->assign($assign, $output);
else
{
echo $output;
}
}
}
}
<?php
$_block_repeat = false;
smarty_block_m3_validate_box($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat);
您的代码中有很多打开和关闭括号错误smarty_block_m3_validate_box
我不知道,这一定是某种自定义功能。它包含什么?可能是smarty模板引擎的一部分。我认为这是因为函数中使用了一些参数作为引用,所以不能直接传递函数调用。例如,array_pop。尝试将array_pop的返回值放入一个变量中,然后将该变量传递到函数中。我尝试了这个方法,但没有成功。谢谢你的回复。是的,同样的错误信息。当试图在站点后端保存/编辑大量内容时,会出现此错误。