正如你在照片中看到的
PHP documentation
DateTime::u构造返回新的
日期时间
对象
以及
public DateTime::u构造([string$time=“now”[,DateTimeZone
$timezone=NULL]])
所以约会时间需要
字符串
但你给它一个
DateTime对象
function getMonthDiff()
{
$currentDateTime = new \DateTime;
$dateTimeInTheFuture = $this->getSalarie()->getDateEmbauche();
$dateInterval = $dateTimeInTheFuture->diff($currentDateTime);
$totalMonths = 12 * $dateInterval->y + $dateInterval->m;
return $totalMonths;
}