以下代码使“ res”的内存地址无限打印。我试图取消引用“ res”变量,以便它输出m_val。你知道为什么它无限打印吗?
$my_controllers = array();
$directory = opendir(APPPATH."controllers");
while($file = readdir($directory)){
if($file != "index.html" && $file != "." && $file != "..") array_push($my_controllers, strtolower(str_replace(".php", '', $file)));
}
$max_categories = 5; //if your need more add $params in the anonymous function, if you need less, only change the num
$temp_path = "";
for($i=0;$i<=$max_categories;$i++){
if($i!=0) $temp_path .= '/';
$temp_path .= '(:any)';
$route[$temp_path] = function ($param0="",$param1="",$param2="",$param3="",$param4="",$param5="") use ($i,$my_controllers){
$temp_cond = false;
foreach ($my_controllers as $value) {
$temp_cond = $temp_cond || $param0 == $value;
}
if($temp_cond){
$temp_return = $param0;
for($j=1;$j<=$i;$j++){
$temp_return .= '/';
$varvar = "param$j";
$temp_return .= $$varvar;
}
return $temp_return;
}
else return 'route';
};
}
还有其他我尝试打印的内容,而不是打印语句中的“ *(&res)”:
答案 0 :(得分:2)
根据上面的评论,以下作品:
out << &res << ": " << res.m_val << "\n";