Re: Patch: Marking DateTime Instances Immutable

From: Date: Sun, 05 Dec 2010 16:18:46 +0000
Subject: Re: Patch: Marking DateTime Instances Immutable
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-50850@lists.php.net to get a copy of this message
> You don't need to know if the instance is immutable or not, since the current DateTime > instances also return themselves for method chaining. So any code that looks like: > > $d = $d->modify("+1 hour"); > > would work no matter mutable/immutable. This is still a bit strange though. But still any > DateTimeValue would extend DateTime. So when you typehint > for a "DateTime", you still don't know if you get the one or the other and you > would have to resort to the previous code example anyways. I do need to know if the instance is immutable. I have plenty of class methods that modify the DateTime instance and some don't return the DateTime instance back. If you want to make sure the object is immutable, you typehint for a DateTimeValue object. From an OO perspective, it makes much more sense to extend the class and add this functionality than to change the inner workings of the existing class. -- Herman Radtke hermanradtke@gmail.com | http://hermanradtke.com

« previous php.internals (#50850) next »