Be carreful about this bug in php 5.6 and lower (fixed in php 7.0 and higher) :
<?php
$date = new DateTime("first day of last month");
echo $date->format('Y-m-d');
echo ' => ' ;
$date->setDate(2013, 2, 3);
echo $date->format('Y-m-d');
?>
Output <=5.6 : 2017-03-01 => 2013-02-01
Output >=7.0 : 2017-03-31 => 2013-02-03
Same goes for "Last day of last month", and the funny part, it will take the last day of the new month setted by setDate
Example with a Leap Year :
<?php
$date = new DateTime("last day of last month");
echo $date->format('Y-m-d');
echo ' => ' ;
$date->setDate(2012, 2, 3);
echo $date->format('Y-m-d');
?>
Output <=5.6 : 2017-03-31 => 2012-02-29
Output >=7.0 : 2017-03-31 => 2012-02-03