1
为了设置创建发票的截止日期,我在使用Symfony2中的格式函数尝试向表中插入日期间隔时遇到了一些麻烦。DateTime格式期望参数1是字符串,给定的对象 - Symfony2
以下是我有:
$today = new \DateTime();
$interval = $today->add(new \DateInterval('P1M'));
$invoice->setDueDate($interval->format('Y-m-d H:i:s'));
然而,当我悬停在PHPStorm format参数,它告诉我,它期待一个DateTime对象不是一个字符串,我得到了下面的错误我探查:
Error: Call to a member function format() on string
所以,我改了行这样:
$invoice->setDueDate($interval->format(new \DateTime()));
但是,当我运行,我的分析器给出了这个错误:
Warning: DateTime::format() expects parameter 1 to be string, object given
它几乎看起来像一个赶上22的情况!我真的很困惑,我使用一个字符串或DateTime对象,因为任何一个失败,但警告我,我需要使用一个或另一个..
任何想法?
你是绝对正确的 - 我只需要默认的格式,所以真的不需要声明它!谢谢! –