English 中文(简体)
我的变量为什么会发生这种情况?
原标题:Why is this happening with my variables?
  • 时间:2012-04-19 19:25:08
  •  标签:
  • php
<?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");
}

When I call dList::lessAnchor() on $searchResult, it modifies the property of $searchData->Page by decreasing it by 1 as you see, marked at line with (!1). After a while (one line below), I call dList::moreAnchor() on $searchResult again.

为什么我看<代码>Page属性在<代码>(!2)上下降1? 我没有通过<代码>查询<>。

最佳回答

查阅:这是打算的行为。

截至购买力平价5,一个物体变量的吨数含有该物体本身的价值。 它只包含一个物体识别标志,允许物体进入者找到实际物体。 如果某一物体通过论证、送回或转让给另一个可变<>/strong>,则不同的变数不是别的:y 持有识别符号的复制件,标明同一物体

如果你想避免这种情况的话,请clone Youbject, 哪里是免费的。 这只是:

public static function lessAnchor(Outcome $searchResult){
  $searchData = clone $newResult->searchData; //$searchData now is a new object
  $searchData->Page=$searchData->Page-1; // (!1)
  return self::basicAnchor($searchData,"Back");
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...