このコードは、私が見ることができるものから10〜15年前に書かれました。金曜日、ウェブホストはphp4のサポートを停止し、強制的に5.6.23にアップグレードし、Webアプリケーションは動作しなくなりました。私は週末を通してそれを乗り越えてきました。システムを稼働させましたが、重大な問題が1つあります。コードの特定の行に絞り込みましたが、自分自身でPHP OOPプログラミングをしていないため、まだ理解できません。私の友人が水の中で死んでいるので、ここで簡単な修正を探しています。PHP OOPコードがphp4を壊しました。 〜php5.6
このコード:
$ins = & $_SESSION["ins"];
$serv = new Services();
print "post - ";
print_r($_POST)."<br />";
reset($_POST);
foreach ($_POST as $key => $value) {
//$key = addslashes($key);
$query = mysql_query("SELECT $valueNumber
FROM CLIENTS_SERVICES
where serviceID = '$key' and clientID = '$ins->client' and effectiveDate <= '$effectiveDate'
order by effectiveDate DESC LIMIT 1")
or die("SELECT services function query failed!!");
$query_data = mysql_fetch_object($query);
$serv->value = $query_data->$valueNumber;
$serv->quantity = $value;
$ins->services[$key] = $serv; //<----- this is the offender
// Calculate services running total
$total = $total + ($serv->quantity * $serv->value);
print $key." - key<br />";
print $value." - value<br />";
print "serv array - ";
print_r($serv);
print "<br />";
print "ins array - ";
print_r($ins->services);
print "<br />";
print $total." - total<br />";
}
出力:一言で言えば
post - Array (
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] => 1.5
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] => 3
[17] =>
[50] =>
[51] => 1.75
[58] =>
[save_services] => Save)
6 - key
1.5 - value
serv object - Services Object ([quantity] => 1.5 [value] => 56)
ins array - Array ([6] => Services Object ([quantity] => 1.5 [value] => 56))
84 - total
16 - key
3 - value
serv object - Services Object ([quantity] => 3 [value] => 45)
ins array - Array ([6] => Services Object ([quantity] => 3 [value] => 45) [16] => Services Object ([quantity] => 3 [value] => 45))
219 - total
51 - key
1.75 - value
serv object - Services Object ([quantity] => 1.75 [value] => 118)
ins array - Array ([6] => Services Object ([quantity] => 1.75 [value] => 118) [16] => Services Object ([quantity] => 1.75 [value] => 118) [51] => Services Object ([quantity] => 1.75 [value] => 118))
425.5 - total
は、私は、最新のオブジェクトの値が前の配列エントリを上書きしている理由を理解することはできません。私は週末に古いバージョン(4.?)と新しい5.6.23の間で何が変わったかを調べようと努力し、数十の死んだ終わりと野生のガチョウの追跡を続けてきました。無知は至福ではありません。
解像度へのポインタがある場合、またはいくつかの洞察力を提供できる場合は、私はそれを感謝します。
を同じポインタを使用します
ループの内部でサービスの新しいインスタンスを作成します。 ](http://stackoverflow.com/q/12859942/1255289)、維持されていない、そして安全でない。それらを取り除く! – miken32
'$ serv'と' $ ins'はどこから来たのかわかりません:http://php.net/manual/en/language.oop5.references.php – AbraCadaver
PHP移行のページ:https:// secure .php.net/manual/en/migration5.php –