On Mon, 10 Dec 2012 16:09:36 +0400, Christian Stoller <stol...@leonex.de> wrote:

Hi internals,

what do you think about improving the modification functionality of the DateTime class. I always get a cold shiver, when I write something like this:
<?php
$date = new DateTime()
$date->modify(‘+15 day’);

In my opinion it would be nicer if one could write:
$date->modify(15, DateTime::INTERVAL_DAY); // for adding 15 days
$date->modify(-15, DateTime::INTERVAL_DAY); // for subtracting 15 days

Even better would be to have methods like addDays(), addMonths(), etc.

This would make it cleaner and more readable. You do not have to do something like this:

$date = new DateTime();
$date->modify(getDaysToAddMethod() . " day"); // I am not sure if a '+' sign is needed if the value is positive

And it is fully backward compatible.

Best regards
Christian


Hi,

I think we shouldn't improve this functionality because modifying date object in the first place is bad idea. Think about it as monatomic object, like integer, you can't create new integer object of 42 and then just change its value - it will be another object.

As a workaround you could create your own date class, extend it from \DateTime and add what you want.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to