[英]Strict standards error?
下面的代碼在一段時間前可以正常工作,但是,當我現在嘗試使用它時,它表示此行有錯誤:
$date1 = new DateTime(array_shift(array_values($array_of_dates)));
錯誤說:
Strict Standards: Only variables should be passed by reference in /home/...
下面是我的代碼:
public function get_user_weeks($user_id,$getdays = NULL,$before_num_days = NULL) {
$weeks_between =0;
$pgql = mysql_query("SELECT at_time FROM users WHERE track_id='$user_id' ORDER BY at_time ASC");
$array_of_dates = array();
while ($row = mysql_fetch_array($pgql, MYSQL_ASSOC)) {
$array_of_dates[] = $row['at_time'];
}
$date1 = new DateTime(array_shift(array_values($array_of_dates)));
if ($before_num_days==NULL) {
$date2 = new DateTime(date("Y-m-d h:m:s")); }
else {
$date2 = date("Y-m-d h:m:s");
$date2 = strtotime('+'.$before_num_days.' day', strtotime($date2));
$date2 = date('Y-m-d h:m:s',$date2);
$date2 = new DateTime($date2);
}
$interval = $date1->diff($date2);
if(NULL == $getdays) {
$weeks_between = (($interval->d) + (30.5 * $interval->m) + (365 * $interval->y))/7; }
else {
$weeks_between = (($interval->d) + (30.5 * $interval->m) + (365 * $interval->y));
}
return $weeks_between;
}
它由array_shift()
觸發,因為它需要一個變量而不是一個值作為參數。
$values = array_values($array_of_dates);
$value = array_shift($values);
$date1 = new DateTime($value);
另外,請注意,MySQL擴展已被正式棄用。 改用MySQLi
或PDO
。
array_shift需要一個參考,因此您需要像這樣更改代碼:
$values = array_values($array_of_dates);
$values = array_shift($values);
$date1 = new DateTime($values);
這是因為返回了引用...在這種情況下,請將其分配給變量並解決此問題。
你可以這樣...
$date1 = new DateTime($dt=array_shift(array_values($array_of_dates))); //Check the variable $dt ;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.