#23537 [Opn]: Abstraction problem in Date class

From: Date: Thu, 08 May 2003 01:00:22 +0000
Subject: #23537 [Opn]: Abstraction problem in Date class
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16045@lists.php.net to get a copy of this message
ID: 23537 User updated by: eddieajau at iprimus dot com dot au Reported By: eddieajau at iprimus dot com dot au Status: Open Bug Type: PEAR related Operating System: WinXP PHP Version: 4.3.2RC2 New Comment: Here's another similar issue. Just downloaded the latest CVS copies to test. The new Date constructor is excellent so I don't need to overload it. However, the following change needs to be made to make it work with my extended class: } elseif (is_object($date) && (get_class($date) == 'date')) { needs to be: } elseif (is_object($date) && (get_class($date) == get_class($this))) { My extended class is called CDate so the constructor complains in the following situtation: $date1 = new CDate(); // class extended from Pear/Date $date2 = new CDate( $date1 ); Regards, Andrew Eddie Previous Comments: ------------------------------------------------------------------------ [2003-05-07 19:11:24] eddieajau at iprimus dot com dot au For the Date package maintainers I've found a slight flaw that prevents proper inheritance of the Date class if you are extending it (as I am to try and preserve the original Pear package as much as possible). For example, in the after method is the following line of code: if(Date::compare($this,$when) == -1) return true; If I have overloaded the compare method (which I have) then my extended class will fail. The compare method should be called like this to provide proper inheritance/overloading properties: if($this->compare($this,$when) == -1) return true; A similar, but much more extensive, problem exists if I want to create an extended Date_calc class. There are to many embedded Date_calc:xxx calls in the Date class to make this feasible and I am force to 'tweak' the Pear source (which I'd like to avoid). Could the Date_calc utility methods not be a part of the Date class itself? Regards, Andrew Eddie ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23537&edit=1

« previous php.pear.dev (#16045) next »