可捕获的致命错误:DateTime类的对象无法转换为字符串


Catchable fatal error: Object of class DateTime could not be converted to string

这是我得到的数组

 Array
(
[0] => BugHerd_Project Object
(
    [id:BugHerd_Project:private] => 24323
    [name:BugHerd_Project:private] => bugherd a
    [devurl:BugHerd_Project:private] => http://st.com/a/
    [active:BugHerd_Project:private] => 1
    [created:BugHerd_Project:private] => DateTime Object
        (
            [date] => 2014-05-03 11:15:22
            [timezone_type] => 2
            [timezone] => Z
        )
    [updated:BugHerd_Project:private] => DateTime Object
        (
            [date] => 2014-05-05 06:55:52
            [timezone_type] => 2
            [timezone] => Z
        )
)

)

/* *获取项目最后创建的日期* @return DateTime项目创建日期*/

public function getCreated() {
return $this->created;
 }
  • 我已经写了下面的代码从数组

    访问日期

    on do print_r($projects_particular->getCreated());

    数组的输出在这里:

      DateTime Object
     (
     [date] => 2014-05-05 10:04:30
    [timezone_type] => 2
    [timezone] => Z
      )
    

    i received error:Catchable fatal error: Object of class DateTime无法转换为string

    • 我只是想访问日期。
public function getCreated() {
return $yourarray->created->date;
 }
public function getid(){
   return $yourarray->id
}