Skip to content

Implemented request #71520 (Adding the DateTime constants to the DateTimeInterface interface) #2483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Majkl578
Copy link
Contributor

Implements FR #71520.

The primary motivation should be obvious from the feature request. Currently it's not possible to properly use DateTimeImmutable formatting, because one needs to use DateTime anyway, since the constants are defined only on DateTime class.

@nikic nikic requested a review from derickr May 1, 2017 10:52
@nikic
Copy link
Member

nikic commented May 1, 2017

Note that this change is technically BC breaking, because constants defined in interfaces cannot be overridden. I don't think that's a blocker for landing in master though.

Copy link
Member

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, but I'd split up the test cases.


print "\n";

var_dump(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding to this test case, I think the additions should go into a new test case (or test cases).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a separate test for each of DateTime/DateTimeImmutable/DateTimeInterface.

@Fleshgrinder
Copy link
Contributor

Note that this change is technically BC breaking, because constants defined in interfaces cannot be overridden. I don't think that's a blocker for landing in master though.

It does result in a fatal error thought, not sure how common it is that people define these constants themselves in their extending classes. The problem is, that any library that does will have a hard time working around this.

@Majkl578
Copy link
Contributor Author

Majkl578 commented May 28, 2017

Updated.

constants defined in interfaces cannot be overridden

It does result in a fatal error

Interesting, because the following code works just fine...

<?php

class Foo extends DateTimeImmutable
{
        const W3C = 'Y';
}

echo DateTimeInterface::W3C, PHP_EOL; // Y-m-d\TH:i:sP
echo Foo::W3C, PHP_EOL; // Y

@nikic
Copy link
Member

nikic commented Jun 2, 2017

@Majkl578 Heh, https://3v4l.org/V7DiV vs https://3v4l.org/JZBZg. Looks like the check only kicks in if you change it directly in the class that implements the interface, but not if there's at least one class in between. So looks like this isn't a BC break after all.

@nikic
Copy link
Member

nikic commented Jun 2, 2017

Merged as 637714c into master. Thanks!

@nikic nikic closed this Jun 2, 2017
@Majkl578 Majkl578 deleted the request-71520 branch June 3, 2017 01:24
@Fleshgrinder
Copy link
Contributor

@Majkl578 not sure why that is the case, probably because an interface that is defined internally behaves differently than an interface in userland: https://3v4l.org/bNRQu This is of course bad, very bad in this case, but would change the game for this PR in terms of being a breaking change.

@Majkl578
Copy link
Contributor Author

@Fleshgrinder Actually, this seems to be a case pointed out by @nikic - it's only checked for direct descendants, even in user-land. See https://3v4l.org/m5Pfp.

@Fleshgrinder
Copy link
Contributor

Now that’s weird behavior. 😅 Well, in that case this PR will be fine for everybody because it is using other magic to prevent implementation in userland.

@derickr
Copy link
Member

derickr commented May 13, 2018

This change doesn't seem to be reflected in the documentation yet. See http://php.net/manual/en/class.datetimeinterface.php vs http://php.net/manual/en/class.datetime.php — please fix that.

@cmb69
Copy link
Member

cmb69 commented Sep 20, 2018

salathe pushed a commit to salathe/phpdoc-en that referenced this pull request Sep 20, 2018
Cf <php/php-src#2483>.
We keep the old IDs, though, for BC reasons. 

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@345663 c90b9560-bf6c-de11-be94-00142212c4b1
svn2github pushed a commit to svn2github/phpdoc_en that referenced this pull request Sep 21, 2018
Cf <php/php-src#2483>.
We keep the old IDs, though, for BC reasons. 

git-svn-id: http://svn.php.net/repository/phpdoc/en@345663 c90b9560-bf6c-de11-be94-00142212c4b1
heiglandreas pushed a commit to phpdoctest/en that referenced this pull request Feb 4, 2020
Cf <php/php-src#2483>.
We keep the old IDs, though, for BC reasons. 

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@345663 c90b9560-bf6c-de11-be94-00142212c4b1
salathe pushed a commit to salathe/phpdoc-en that referenced this pull request Sep 3, 2020
Cf <php/php-src#2483>.
We keep the old IDs, though, for BC reasons. 

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@345663 c90b9560-bf6c-de11-be94-00142212c4b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants