perchè gli passavi strtotime, che non è una stringa, ma un time appunto, tantè che:
Codice PHP:
<?php
$test = '2014-02-12';
$data = new DateTime($test);
echo $data->format('d-m, Y');
echo "\n\n";
$data2 = new DateTime(strtotime($test));
echo $data->format('d-m, Y');
restituisce:
codice:
12-02, 2014 #### PRIMO format(), OUTPUT CORRETTO
PHP Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1392159600) at position 7 (6): Unexpected character' in /xxx/test.php:11
Stack trace:
#0 /xxxx/test.php(11): DateTime->__construct('1392159600')
#1 {main}
thrown in /xxx/test.php on line 11
perchè il costruttore di DateTime si aspetta una stringa rappresentante una data, non il timestamp restituito da strtotime