php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23537 Abstraction problem in Date class
Submitted: 2003-05-07 19:11 UTC Modified: 2003-12-09 07:10 UTC
From: eddieajau at iprimus dot com dot au Assigned: pajoye (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.2RC2 OS: WinXP
Private report: No CVE-ID: None
 [2003-05-07 19:11 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-07 20:00 UTC] eddieajau at iprimus dot com dot au
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
 [2003-05-11 01:25 UTC] mj@php.net
Fixing all of these points look safe to me. I've assigned the bug to the maintainer, hoping the he'll fix it.
 [2003-06-02 13:36 UTC] baba@php.net
have a couple of other fixes/additions that i've been meaning to merge into Date... i will try to take a look at this as well.
 [2003-12-09 07:10 UTC] pajoye@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 02:01:23 2021 UTC