DateTime::uu construct()要求参数1为字符串,对象为给定值
这是函数:
function getMonthDiff() { $currentDateTime = new \DateTime; $dateTimeInTheFuture = new \DateTime($this->getSalarie()->getDateEmbauche()); $dateInterval = $dateTimeInTheFuture->diff($currentDateTime); $totalMonths = 12 * $dateInterval->y + $dateInterval->m; return $totalMonths; }
{{ entity.monthDiff }}
这是getDateEmbauch函数
public function getDateEmbauche(): ?\DateTimeInterface { return $this->dateEmbauche; }
正如你在照片中看到的 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; }