0

here is my array i get

 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
        )

)

)

/** * Gets date the project was last created * @return DateTime Project creation date */

public function getCreated() {
return $this->created;
 }
  • i have written below code for to access date from array

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

    output of array is here :

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

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

    • im just want to access date.
user3306026
  • 122
  • 3
  • 16
  • is this the `DateTime` object? to return a string, you should use `format()` – kennypu May 05 '14 at 11:24
  • 1) That's not an array, it's an object of class `DateTime` (it says so in the printout). 2) "Want to access date" is unclear. Would you be OK with printing the date as the number of microseconds elapsed since my birthday? If not, why not? – Jon May 05 '14 at 11:24
  • This question has been asked multiple times: http://stackoverflow.com/questions/19134174/symfony2-catchable-fatal-error-object-of-class-datetime-could-not-be-converted – user2886138 May 05 '14 at 11:24
  • check my updated array that i want – user3306026 May 05 '14 at 11:33

1 Answers1

2
public function getCreated() {
return $yourarray->created->date;
 }

public function getid(){
   return $yourarray->id
}
Babu
  • 605
  • 7
  • 24