Search code examples
phpphp-5.3pleskcentos6

DateTime not responding on server change


I recently migrated a site from a shared hosting to a Virtual Private Server. On the shared hosting I had PHP 5.2, and on the VPS I have PHP 5.3.3. After this migration the DateTime class stopped responding. the following code used to work fine but now I only get the $test output.

$test = $vMonth.'/'.$vDay.'/'.$vYear;
echo $test;
$date = new DateTime($test);
if (!$date) {
    $e = date_get_last_errors();
    foreach ($e['errors'] as $error) {
        echo $error."\n";
    }
    echo "step1";
} else {
    echo $date;
    echo "step2";
}
$vBday = date_format($date, 'Y-m-d H:i:s');
echo "Test0";

Does anybody know if this is a known issue? or if there is a workaround? Thank you!

EDIT (php.ini):

error_reporting = E_ALL & ~E_DEPRECATED
log_errors = On
display_errors = On
error_log = /tmp/php_errors.log

Solution

  • I found a solution to my problem. Apparently, a lot of work was done on 5.3 to this class. Mostly to support European+American date style and to add support to more formats. This must have included unexpected changes to the constructor, because it was not recognizing my previous formatting. The solution was to go for create from format and ISO 8601:

    $test = $vYear.'-'.$vMonth.'-'.$vDay;
    $date = date_create_from_format("Y-n-j",$test);
    $vBday = date_format($date, 'Y-m-d H:i:s');