本文介绍了PHP:只能通过引用传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在第 57 行收到此错误:$password = str_replace($key, $value, $password, 1);
I am getting this error on line 57: $password = str_replace($key, $value, $password, 1);
据我所知,我只是传入变量.以下是更多背景信息:
As far as I can tell, I am only passing in variables. Here is some more context:
$replace_count = 0;
foreach($replacables as $key => $value)
{
if($replace_count >= 2)
break;
if(strpos($password, $key) !== false)
{
$password = str_replace($key, $value, $password, 1);
$replace_count++;
}
}
推荐答案
您不能传递 1 的常量,解决方法是将其设置为变量.
You can't pass a constant of 1, a fix is to set it to a variable as so.
变化:
$password = str_replace($key, $value, $password, 1);
到:
$var = 1
$password = str_replace($key, $value, $password, $var);
更新: 更改为在方法调用之外根据评论中的反馈声明变量.
UPDATE: Changed to declare variable outside of the method call from feedback in comments.
这篇关于PHP:只能通过引用传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!