Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Larry Garfield
I'd love to have a Value Object version of DateTime, as its current behavior is quite annoying. However, making it a toggle on the existing class does not make sense to me. A function or method that gets called with a DateTime object then doesn't know if it is safe to modify or not, and if

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Benjamin Eberlei
Hey Larry, 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

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Herman Radtke
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

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Benjamin Eberlei
On Sun, 5 Dec 2010 08:18:46 -0800 Herman Radtke hermanrad...@gmail.com wrote: 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

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread troels knak-nielsen
On Sun, Dec 5, 2010 at 6:44 PM, Benjamin Eberlei kont...@beberlei.de wrote: So currently preferred over my patch are two solutions: 1. Just create a DateTimeValue object that is immutable, not optimizing PHP to handle it with efficient garbage collection. 2. One step further, add a static

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Stas Malyshev
Hi! I propose to allow to work with DateTime objects that are marked as immutable optionally. This means that all methods add, sub, modify, I think it's a bad idea, which would instantly break all the code that assumes different semantics. Yes, I noticed the word optional, however, the code

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Pierre Joye
On Sun, Dec 5, 2010 at 7:02 PM, troels knak-nielsen troel...@gmail.com wrote: On Sun, Dec 5, 2010 at 6:44 PM, Benjamin Eberlei kont...@beberlei.de wrote: So currently preferred over my patch are two solutions: 1. Just create a DateTimeValue object that is immutable, not optimizing PHP to

RE: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Jonathan Bond-Caron
On Sun Dec 5 12:44 PM, Benjamin Eberlei wrote: 1. Just create a DateTimeValue object that is immutable, not optimizing PHP to handle it with efficient garbage collection. 2. One step further, add a static class DateTimeValue like syntax that creates an immutable class. Any ideas? Some

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Benjamin Eberlei
On Sun, 05 Dec 2010 10:29:29 -0800 Stas Malyshev smalys...@sugarcrm.com wrote: Hi! I propose to allow to work with DateTime objects that are marked as immutable optionally. This means that all methods add, sub, modify, I think it's a bad idea, which would instantly break all the code

Re: [PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-05 Thread Stas Malyshev
Hi! i actually implemented this in userland, but its rather ugly: It is ugly because you try to have one class with two semantics. It is a mistake. If you remove this ambiguity it actually would be quite small. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/

[PHP-DEV] Patch: Marking DateTime Instances Immutable

2010-12-04 Thread Benjamin Eberlei
In the current implementation DateTime is not a value object, but its internal state can be modified at any given time. This can lead to very obscure bugs when references to DateTime objects are shared or objects are passed through a chain of methods/functions that modify it. Using DateTime is