Skip to content
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

Typed constants in date extension #12361

Merged
merged 8 commits into from
May 22, 2024

Conversation

jorgsowa
Copy link
Contributor

@jorgsowa jorgsowa commented Oct 4, 2023

This PR adds types to the constants in Date extension.

@jorgsowa jorgsowa requested a review from derickr as a code owner October 4, 2023 20:58
@jorgsowa jorgsowa force-pushed the typed-constants-in-date-extension branch from 3fa369f to 01201f7 Compare October 29, 2023 17:19
@kocsismate
Copy link
Member

LGTM but let's wait for Derick's review

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.

How is this not a BC break?

<?php
class MyDateTime extends DateTime {
	const COOKIE = "I love cookies";
}

Used to work, but now no longer does.

/**
* @tentative-return-type
*/
/** @tentative-return-type */
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unnecessary formatting changes.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, IMO this is an useful change, makes the stub much shorter and easier to overview. Actually, I asked the same in different extensions.

Copy link
Member

Choose a reason for hiding this comment

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

They shouldn't be in the same commit (which it will end up in after squashing), and hence, shouldn't be part of this PR to begin with.

* @cvalue PHP_DATE_TIMEZONE_PER_COUNTRY
*/
public const PER_COUNTRY = UNKNOWN;
/** @cvalue PHP_DATE_TIMEZONE_GROUP_AFRICA */
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unnecessary formatting changes (just remove the @var int line).

/**
* @tentative-return-type
*/
/** @tentative-return-type */
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unnecessary formatting changes.

/**
* @strict-properties
*/
/** @strict-properties */
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unnecessary formatting changes.

@kocsismate
Copy link
Member

How is this not a BC break?

Yes it is a BC break, that's why the change is mentioned in the UPRADING file. BTW why would you want to overwrite ext/date's constants? Do you have a legitimate use-case?

@jorgsowa jorgsowa force-pushed the typed-constants-in-date-extension branch from 01201f7 to 16675d6 Compare November 26, 2023 23:26
@jorgsowa
Copy link
Contributor Author

@derickr, thank you for the review. I agree this is BC, but it's small enough so I thought it's safe to merge. I think Date extension is the last one that has not those kind of changes merged.

Regarding the comments I followed similar convention in other extensions, but other comments in the file as well, where comments of 1 line, where changed to 1-line PHPDoc. Similarly to the lines 662 and 665. https://github.com/php/php-src/pull/12361/files#diff-69c5b7520e110ac19361b7b043c1e2b75b8b11c9154557b1927491db2a47643aL662

Should I change it back?

@kocsismate kocsismate requested a review from nielsdos March 5, 2024 20:00
@kocsismate
Copy link
Member

@derickr Could you please do another review round? Basically all the other internal class constants are typed now, so it would be nice to do the same in ext/date

@jorgsowa jorgsowa force-pushed the typed-constants-in-date-extension branch from 16675d6 to 114422f Compare March 14, 2024 21:07
/**
* @tentative-return-type
*/
/** @tentative-return-type */
Copy link
Member

Choose a reason for hiding this comment

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

They shouldn't be in the same commit (which it will end up in after squashing), and hence, shouldn't be part of this PR to begin with.

@jorgsowa
Copy link
Contributor Author

Thanks, @derickr for the review. I have reverted unrelated PHPDoc changes. I will create another PR for them.

@jorgsowa jorgsowa requested a review from derickr March 19, 2024 07:11
Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

Personally, I'm fine with the PR as is.

@kocsismate kocsismate merged commit c4d9a37 into php:master May 22, 2024
9 of 10 checks passed
@iluuu1994
Copy link
Member

iluuu1994 commented May 23, 2024

This is breaking, see. https://github.com/php/php-src/actions/runs/9200769315/job/25307893880 I think it's a bit early to add these types, because libraries supporting older PHP versions (that are still supported too) won't have a way to override these constants, given that typed class constants were only introduced in PHP 8.3.

@jorgsowa
Copy link
Contributor Author

There is currently no way to deprecate changing the type of the properties so I assume the proper way would be to apply type to new constants only.

I will prepare PR with a revert.

@iluuu1994
Copy link
Member

That said, I don't know why Carbon overrides this constant. Maybe it's a BC layer that's no longer needed? It has the same value as our constant. If you prefer, we can ping them first to see if it is still needed.

@derickr
Copy link
Member

derickr commented May 23, 2024 via email

@iluuu1994
Copy link
Member

I think the BC break would be fine if there was an easy, backwards compatible solution. As of now, I'd prefer reverting this. But I'm not owner of this code, so I'll leave it up to you and @kocsismate.

@kocsismate
Copy link
Member

kocsismate commented May 23, 2024

I had a quick look at their constant usage, and they could have used any other constant... Especially because their override doesn't have any effect on the internal code. So I am wondering if we could selectively revert only the type declaration of DatePeriod::EXCLUDE_START_DATE? I still don't see the point why someone would override these constants. Buy anyway, we can revert the whole change if you want.

@iluuu1994
Copy link
Member

Thanks @kocsismate. Please revert this for now then, so that the build works again. Feel free to ping the Carbon authors and ask whether this constant can be removed on their side, and then reapply accordingly.

@iluuu1994
Copy link
Member

@kocsismate You can wait with reverting this. I just now saw that these changes have already been made to many extensions and it doesn't make sense singling out one extension. I still think it would have been better to wait another release to make these changes, so that a PHP code base can change the signature of overridden constants by adding a type and supporting all officially supported versions. E.g. they may want to add an attribute, which I would consider a valid use-case.

Anyway, we should either revert all or none of them. I'm creating a PR for Carbon in the meantime.

@kylekatarnls
Copy link
Contributor

Hello everybody, thank you for making me aware of this upcoming change, I'll investigate if this is an issue on our side and get back to you soon.

@kylekatarnls
Copy link
Contributor

So we can safely remove our override so our next version won't have any problem with that and we are not PHP 8.4 ready for other reasons so it does not make a difference neither for our previous versions. No blocker here. Thank you very much for reaching out. 🙏

@kocsismate
Copy link
Member

@kylekatarnls @iluuu1994 Thank you both for taking care of this problem :) I was busy until now with life, but I'm happy to see that the problem is gone.

@jorgsowa jorgsowa deleted the typed-constants-in-date-extension branch August 7, 2024 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants