【发布时间】:2014-11-13 03:34:51
【问题描述】:
我创建了一种使拍卖名称成为网络安全的方法,并且我只是添加了一个重复网络名称检查,它基本上尝试使用给定的网络安全名称获取拍卖,然后向网络名称添加一个随机数。但该方法最终返回 null...
private function dupplicateUrlFix($url){
var_dump($url)//Correct
$existingAuction = Auction::get($url, "webname");
//if webname exists, cancatenate with random int, and check if new webname exists
if(!empty($existingAuction->webname)){
$newUrl = $existingAuction->webname.rand(0,9);
$this->dupplicateUrlFix($newUrl);
return;
}
var_dump($url) //Correct Not a dupplicate
return $url;
}
public function get_url_clean($string) {
$string = strToLower($string);
//cleaning....
//checks for dupplicate
var_dump($this->dupplicateUrlFix($string)); //is null?
die();
return $clean;
}
我尝试在 dupplicateUrlFix() 方法中切换顺序并简单地返回一个字符串。它只进入 if(!empty... 一次。
是否有解决方案或更好的方法?
【问题讨论】:
-
我认为
$existingAuction->webname.rand(0,9)无效。也许做$newUrl = ($existingAuction->webname).rand(0,9) -
@Doctus 间隔为
$newUrl = $existingAuction->webname . rand(0,9)更具有视觉感。 -
@MichaelBerkowski 这是主观的 - 它们都是有效的
-
@Doctus 我没有说你是无效的。我以为您暗示它是无效的,因为该点旨在用作类运算符。我误读了你的评论。
-
哦,我明白你的意思了!是的,我不太确定,但我知道过去在将对象属性与字符串连接时,我必须将它们括在括号中。