2
<?php
// $searchResult is type of Outcome
// This is what we do:
dList::lessAnchor($searchResult)->showElement();
dList::moreAnchor($searchResult)->showElement();
/**
* @returns vAnchor (can get showed with showElement() - not part of the problem)
*/
public static function lessAnchor(Outcome $searchResult){
$searchData = $searchResult->searchData;
$searchData->Page = $searchData->Page - 1; // (!1)
return self::basicAnchor($searchData, "Back");
}
/**
* @returns vAnchor (can get showed with showElement() - not part of the problem)
*/
public static function moreAnchor(Outcome $searchResult){
$searchData=$searchResult->searchData;
$searchData->Page = $searchData->Page + 1; // (!2)
return self::basicAnchor($searchData, "More");
}
當我呼籲$searchResult
dList::lessAnchor()
,它由1降低它修改的$searchData->Page
屬性正如你看到的,在標註符合(!1)
。 經過一段時間(下面一行),我再次撥打$searchResult
致電dList::moreAnchor()
。爲什麼會發生這種情況與我的變量?
爲什麼我看到Page
屬性在(!2)
標記處減1?我沒有通過參考$searchResult
。
哇,現在我沒有想到這一點。我應該在函數調用中克隆對象嗎? - 好吧,我明白了。謝謝你的建議和質量 – Dyin 2012-04-19 19:40:50
是的 - 我剛剛編輯我的答案,提到這一點;) – oezi 2012-04-19 19:42:40