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