Q:

PHP : Very big no sense with variable

I'm working on a Symfony 2 app.
I've an object manage with Doctrine which it has private $beginDate which is a \DateTime.
I've a function very important :
public function isBefore($timestamp)
{
    print_r($this->beginDate);
    echo "<br />";
    $date = $this->beginDate->format("Y-m-d"); // (line 44)
    echo $date;
    echo "<br />";
    return $this->beginDate->getTimestamp() < $timestamp;
}

The first print_r display : DateTime Object ( [date] => 2015-01-01 00:00:00 [timezone_type] => 3 [timezone] => Europe/Paris )
The beginDate->format give me : Error: Call to a member function format() on a non-object in /var/.../GS/AcmeBundle/Entity/ARecur.php line 44
echo $date display : 2015-01-01
And $this->beginDate->getTimestamp() said nothing because the line 44 is blocking others errors (but without the line 44, i've the same error on this line !)
My PHP version :

PHP 5.4.4-14+deb7u14 (cli) (built: Aug 21 2014 08:36:44) 
  Copyright (c) 1997-2012 The PHP Group
  Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Any ideas (Sorry for my bad english)
Have a good day :)

A:

I've found a solution, not nice but it doesn't crash my app :
public function isBefore($timestamp)
{
    $myDate = json_decode(json_encode($this->beginDate), true); 
    return strtotime($myDate['date']) < $timestamp;
}

