chinmay.sahoo
New member
Say payment is due 10 days after delivery. You copy the delivery date and add 10 days to it. If you do that by adding 10 days to the timestamp inside the due date, you’ve also changed the delivery date, which probably isn’t what you intended. The following is a recipe for confusion, if not disaster:
If you thought that $paymentDate is now different from $deliveryDate, you’re right in PHP 4, but wrong in PHP 5.
The previous problem—that both versions of the date change—doesn’t occur in this case. We got $paymentDate by adding to $deliveryDate, but $delivery-Date didn’t change. And no matter what we do to one of them, the other will remain the same. They are separate copies. With objects in PHP 5, it’s different .
What we need is an API that lets us handle time points as if they were plain values. We want to do this:
$deliveryDate = new DateAndTime;
$paymentDate = $deliveryDate;
$paymentDate->addDays(10);
If you thought that $paymentDate is now different from $deliveryDate, you’re right in PHP 4, but wrong in PHP 5.
$deliveryDate = time()
$paymentDate = $deliveryDate + 3600 * 24 * 10;
The previous problem—that both versions of the date change—doesn’t occur in this case. We got $paymentDate by adding to $deliveryDate, but $delivery-Date didn’t change. And no matter what we do to one of them, the other will remain the same. They are separate copies. With objects in PHP 5, it’s different .
What we need is an API that lets us handle time points as if they were plain values. We want to do this:
$deliveryDate = new DateAndTime;
$paymentDate = $deliveryDate->addDays(10);