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

Ensure WP_Text_Diff_Renderer_Table is PHP 8.2 compatible #5453

Conversation

anton-vlasenko
Copy link

@anton-vlasenko anton-vlasenko commented Oct 10, 2023

This PR aims to add missing class properties to ensure WP_Text_Diff_Renderer_Table is PHP 8.2 compatible.

Trac ticket: https://core.trac.wordpress.org/ticket/59431


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…sure compatbility with PHP 8.2.

PHP 8.2 doesn't support dynamic properties.
* @since 6.4.0
* @var string|null
*/
public $_title;
Copy link
Author

Choose a reason for hiding this comment

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

I intentionally didn't initialize these class properties because they used to be set to NULL in the previous implementation. This is to maintain BC.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree, the original default value of null is being maintained.

@anton-vlasenko anton-vlasenko marked this pull request as ready for review October 10, 2023 16:42
@mukeshpanchal27
Copy link
Member

Thank you, @anton-vlasenko, for the PR. Could you also include a brief description indicating that we added these variables for backward compatibility (BC)? This way, we can prevent someone from raising a ticket in the future to remove these variables, claiming they are unused.

@anton-vlasenko
Copy link
Author

Thank you, @anton-vlasenko, for the PR. Could you also include a brief description indicating that we added these variables for backward compatibility (BC)?

Thank you for checking this PR, @mukeshpanchal27!
I've added more detailed descriptions to the class properties in 73ebb73 to clarify their purpose.

This way, we can prevent someone from raising a ticket in the future to remove these variables, claiming they are unused.

If I understand you correctly, you're referring to this comment. These class properties weren't just declared to maintain BC. They were introduced to ensure compatibility with PHP 8.2. What I meant is that these properties are not assigned any value to ensure BC. In my opinion, this doesn't need to be explained in the code. But that's my opinion.

Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

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

Core is using these 3 properties, which prior to this patch, were dynamic properties. With the changes to the magic methods, dynamic properties are deprecated for all PHP versions. Explicitly declaring these properties on the class is a follow-up to that scope of work and is needed.

Changes LTGM 👍 Ready for commit.

@hellofromtonya
Copy link
Contributor

To follow-up on the discussion of these properties:

Anton is right - they are not being declared on the class for BC. Rather, this patch is necessary to explicitly declare the properties that are being used in Core.

Why? Prior to this patch, the properties were dynamic and thus were accessible only through the magic methods. r56354 modified the magic methods for all WP supported PHP versions (not just PHP 8.2+) to raise a deprecation for all dynamic properties.

Core itself though should not be raising this new deprecation as it's properties should all be declared.

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Oct 11, 2023

I first reviewed this patch thinking - yes, let's add the properties as declared. But then looking at r56354 I remember the changes implemented uses the $compat_fields property to access these "declared" properties (compatible fields) through the magic methods.

I wondering .. should these 3 properties also be added to the $compat_fields array of compatible fields, rather than declaring them on the class? In this way, the current behavior is maintained, i.e. these 3 will still use the magic methods as they always have.

@anton-vlasenko @mukeshpanchal27 what do you think?

@anton-vlasenko
Copy link
Author

anton-vlasenko commented Oct 11, 2023

@hellofromtonya I'm looking at https://core.trac.wordpress.org/ticket/56034 and, as far as I understand, the recommended way of dealing with known, named dynamic properties is to declare them on the class.
I'm referring to this part of the ticket (highlighted text):
Screenshot 2023-10-11 at 19 08 30
However, I agree that there is probably less risk in adding these properties to the $compat_fields array than in declaring them on the class. I need to investigate potential BC risks.

@hellofromtonya
Copy link
Contributor

@anton-vlasenko you're right. That is the recommended approach. Thanks for reminding me!

I'm curious of the previous behavior, i.e. before r56354. Let's double check before moving forward with committing this change.

@anton-vlasenko
Copy link
Author

anton-vlasenko commented Oct 11, 2023

Thank you, @hellofromtonya.
Before https://core.trac.wordpress.org/changeset/56354, these properties were dynamic and were never set in the Text_Diff_Renderer's constructor because __isset() returned false. Now, the behavior remains the same. The only difference is that these properties are now declared, so the __isset() magic method is no longer called for them.
IMO, having them declared on the class is fine. But I'm open to hearing alternative opinions.

@hellofromtonya
Copy link
Contributor

Thanks @anton-vlasenko. Testing before and after for these Core specific dynamic properties:

  • Before 6.4: they always returned null and could not be changed / set https://3v4l.org/FrRJL
  • But this PR changes that behavior by allowing them to now be set, but ... that is the plan per proposal on how to deal with "known named dynamic properties".

Known, named, dynamic property | Declare the property on the (parent) class

So the PR as it is now aligns to that plan.

@hellofromtonya
Copy link
Contributor

Committed via https://core.trac.wordpress.org/changeset/56938.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants