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

From: Date: Sun, 05 Dec 2010 19:26:29 +0000
Subject: RE: [PHP-DEV] Patch: Marking DateTime Instances Immutable
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-50860@lists.php.net to get a copy of this message
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 ideas here: http://www.javalobby.org/articles/immutable/index.jsp A pattern I've been using is ~ interface Immutable {} class DateTime_Immutable extends DateTime implements Immutable { // throw exceptions if attempt to modify... } // Get immutable objects... Objects::getImmutable('Datetime', '2009-01-09'); // returns (Immutable) new DateTime_Immutable('2009-01-09') Objects::getImmutable('Datetime', $param1, $param2, ...); // returns (Immutable) new DateTime_Immutable($param1, $param2, ...)

« previous php.internals (#50860) next »