Opened 2 years ago
Closed 17 months ago
#56876 closed defect (bug) (fixed)
Dynamic Properties: Fix magic methods in WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table and WP_Admin_Bar classes
Reported by: | antonvlasenko | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch has-unit-tests php82 early commit reporter-feedback |
Focuses: | Cc: |
Description (last modified by )
WP_List_Table
, WP_User_Query
, and WP_Text_Diff_Renderer_Table
classes implement an incomplete set of magic methods.
But these magic methods need to be refactored to ensure that these classes are compatible with PHP 8.2 (the magic methods in these classes are only partially implemented, the missing/incomplete magic methods should be added/refactored).
Also, developers should get a warning when they try to set (get) dynamic properties on objects of these classes.
As for the WP_Admin_Bar
class: an investigation is needed to decide whether WP_Admin_Bar::__get()
can be removed.
Props to @jrf for identifying the issue .
References:
- These changes were discussed and agreed to in a livestream by @jrf @markjaquith and @hellofromTonya.
- The changes are part of #56034, which is the larger Dynamic Properties proposal and initiative.
Change History (40)
This ticket was mentioned in PR #3535 on WordPress/wordpress-develop by @antonvlasenko.
2 years ago
#4
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
This PR aims to improve the compatibility of the WP_List_Table
class with PHP 8.2 and above by ensuring that developers get a proper error notice when they try to set/get a dynamic property.
Before this PR, WordPress wouldn't display any warning about incorrect usage of dynamic properties.
Trac ticket: https://core.trac.wordpress.org/ticket/56876
This ticket was mentioned in Slack in #core by desrosj. View the logs.
2 years ago
#6
@
2 years ago
- Keywords php82 added
- Milestone changed from Awaiting Review to 6.1.1
- Version trunk deleted
Though 8.2 aims to bring WordPress to a more compatible state with PHP 8.2, this is not a new issue in 6.1
/trunk
, so unsetting the Version field.
Let's take a look at this for 6.1.1 or 6.2, whichever the committers familiar with these efforts are more comfortable with.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
@JeffPaul commented on PR #3535:
2 years ago
#8
@SergeyBiryukov @jrfnl pinging you here in hopes one of you can help give this a review and help it land in 6.1.1... thank you!
@JeffPaul commented on PR #3535:
2 years ago
#9
@hellofromtonya also pinging you as well, any help with review/commit on this for 6.1.1 would be appreciated... thank you!
#10
@
2 years ago
The linked pull request includes a new string, 'The "%1$s" property isn\'t defined. Dynamic properties are deprecated in PHP 8.2 and above.'
.
I think 6.2 would be better, if possible, to avoid the need for new language packs.
#12
follow-up:
↓ 13
@
2 years ago
- Milestone changed from 6.1.1 to 6.2
At first, I was a +1 to include this in 6.1.1. However, this addresses only 1 specific class of potentially many with this issue.
There is a really detailed plan for addressing this laid out in #56034, and I think that this should be evaluated within the context of that plan.
It's highly preferable that all of the classes with this problem get fixed at the same time.
Moving this to 6.2
to match the current milestone for #56034.
#13
in reply to:
↑ 12
@
2 years ago
Replying to desrosj:
At first, I was a +1 to include this in 6.1.1. However, this addresses only 1 specific class of potentially many with this issue.
There is a really detailed plan for addressing this laid out in #56034, and I think that this should be evaluated within the context of that plan.
It's highly preferable that all of the classes with this problem get fixed at the same time.
It may be more convenient to have everything in one PR, but that PR is going to be pretty large (given that each class that is being fixed also needs unit tests).
Discussing fixes for each class can also take a long time, delaying the deployment of the fix.
So, from my point of view, it will be more convenient to release fixes gradually as they get approved.
@antonvlasenko commented on PR #3535:
23 months ago
#14
I want to add a fix for another class to this PR because the fixes are similar.
So please don't review for now.
#15
@
23 months ago
- Summary changed from WP_List_Table should prevent using dynamic properties as they are not allowed in PHP 8.2 to WP_List_Table and WP_User_Query should prevent using dynamic properties as they are not allowed in PHP 8.2
The PR is ready to be reviewed.
Sorry for spamming, but I couldn't find a way to edit my previous message.
#17
@
22 months ago
- Summary changed from WP_List_Table and WP_User_Query should prevent using dynamic properties as they are not allowed in PHP 8.2 to WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table classes should prevent using dynamic properties as they are not allowed in PHP 8.2
It's highly preferable that all of the classes with this problem get fixed at the same time.
I've closed https://core.trac.wordpress.org/ticket/57570 in favor of this task and cherry-picked all related changes to https://github.com/WordPress/wordpress-develop/pull/3535.
This ensures that all the classes with this problem get fixed simultaneously.
@desrosj Please let me know if I should also cherry-pick changes from https://core.trac.wordpress.org/ticket/56535 and close it in favor of this ticket.
@audrasjb commented on PR #3535:
22 months ago
#19
Hi there, thanks for the PR!
I added a few very small change requests.
#20
@
22 months ago
- Summary changed from WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table classes should prevent using dynamic properties as they are not allowed in PHP 8.2 to Refactor magic methods in WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table and WP_Admin_Bar classes
Updated description for this ticket (I'm unable to change it with my .org account):
WP_List_Table
, WP_User_Query
, and WP_Text_Diff_Renderer_Table
classes implement some magic methods.
But these magic methods need to be refactored to ensure that these classes are compatible with PHP 8.2 (the magic methods in these classes are only partially implemented, the missing/incomplete magic methods should be added/refactored).
Also, developers should get a warning when they try to set (get) dynamic properties on objects of these classes.
As for the WP_Admin_Bar
class: an investigation is needed to decide whether WP_Admin_Bar::__get()
can be removed.
#22
@
22 months ago
- Owner set to hellofromTonya
- Status changed from new to reviewing
Self-assigning for review.
#23
@
22 months ago
- Keywords early added
- Milestone changed from 6.2 to 6.3
Re-listening to the livestream (ie where @jrf @markjaquith and I discussed these changes), consensus was to commit these changes when the alpha branch is first opened. Why? To give the longest amount of time possible for feedback and reports of issues.
Punting this ticket to 6.3 early
. The 6.3 alpha will happen after 6.2-RC1 which is coming fast (less than 2 weeks away). The plan is to finish the reviews and patches (1 patch per class) and then commit each once alpha is open.
This ticket was mentioned in PR #4133 on WordPress/wordpress-develop by @antonvlasenko.
22 months ago
#24
## This is a draft PR. Please don't review.
This PR aims to refactor WP_Admin_Bar and remove the __get
magic method. Magic methods are deprecated in PHP 8.2.
Trac ticket: https://core.trac.wordpress.org/ticket/56876
@hellofromTonya commented on PR #3535:
21 months ago
#25
Closing this PR. Instead each of these classes will get a separate PR and commit to encapsulate their contextual history and individual considerations.
@hellofromTonya commented on PR #4133:
21 months ago
#26
Context for these changes were shared here https://github.com/WordPress/wordpress-develop/pull/3535#discussion_r1115026361. Copying them here.
Reviewing the first query for
menu
shows that at least 1 plugin (s2 Member Framework) is using this property.
As discussed in the livestream, the plan is:
- Remove the
__get()
.- Since
menu
is being used, add it as a public property on the class with a default value ofarray()
./** * Deprecated menu property. * * @since 3.1.0 * @deprecated 3.3.0 Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(). * @var array */ public $menu = array();
- What about
proto
(for protocol) property?From the livestream, there was consensus to remove it if _unused_, but with an action to research what the property is and why it was added.
History on the
proto
property:
- r16038 added this property.
- r19501 moved it from the
initialize()
method to__get()
.- When 3.1 released, the protocol handling switched to use
get_admin_url()
,admin_url()
, etc functions instead of theproto
property. But the property remained in the code, unused.Would removing it be a BC break? If not used, then no. But if some plugin or theme in the wild uses it, then yes it is a BC break.
Let's remove it with this reasoning:
- It's unused in Core and none found in wporg search
- It was introduced in the 3.1 cycle but then replaced with URL get functions during that same cycle.
- It's reasonable then to say that it should have been removed in 3.1, but was missed. It appears to be dead code.
#27
@
21 months ago
- Summary changed from Refactor magic methods in WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table and WP_Admin_Bar classes to Dynamic Properties: Fix magic methods in WP_List_Table, WP_User_Query, WP_Text_Diff_Renderer_Table and WP_Admin_Bar classes
#28
@
21 months ago
- Keywords commit added
Patch: https://github.com/WordPress/wordpress-develop/pull/4133
This patch:
- removes
WP_Admin_Bar::__get()
- declares
menu
as a property on the class and initializes it to an empty array. - removes the unused
proto
dynamic property.
Why remove the proto
?
tl;dr
- This property was not intended to be released in 3.1.
- There are no usages of it in WP.org's plugin or theme directory.
- There's consensus from @markjaquith @jrf and me that it's safe to remove
'proto'
. - Plan: Commit early to give time for reports of usages.
More Details:
The protocol handling was added during the 3.1 development cycle but its usage was removed and switched to use get_admin_url()
, admin_url()
, etc functions. WP 3.1.0 shipped with the property in the class, but not used in Core.
During the 3.1 development cycle:
- [16038] added this property to the
WP_Admin_Bar
class and switched it tohttps://
if SSL inWP_Admin_Bar::initialize()
. - [16308] eliminated its usage in Core, but the property remained in
WP_Admin_Bar
. - It appears this property was missed in [16308] and should have been removed before 3.1 shipped.
In WP 3.3, [19501] / #19371 introduced the __get()
magic method for BC of 'menu'
:
Source
making sure that
$this->menu
returns back compat code
We're not going to maintain compat for $menu. Suggest we make it array() and plugins will have to deal. We can throw a
_deprecated_argument()
and push them to use the new methods.
Notice, there's no mention of usages or BC concerns for 'proto'
property, but it too was added to the magic method.
#29
@
21 months ago
I'll let this sit for any further considerations. If none, then will commit on Monday, March 20th.
#30
@
21 months ago
- Description modified (diff)
Updated the ticket's description to include the references to:
- the livestream, where these changes were discussed and agreed to by @markjaquith, @jrf, and me.
- #56034 - as this change is part of that work.
@hellofromTonya commented on PR #4133:
21 months ago
#33
Committed via https://core.trac.wordpress.org/changeset/55580.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
19 months ago
#35
@
19 months ago
- Description modified (diff)
- Keywords reporter-feedback added
This ticket was discussed in the recent bug scrub. It was felt that splitting this into separate tickets would help each move forward and for the respective ticket to be closed in the appropriate milestone (and possibly component).
@antonvlasenko Are you happy to handle the creation of separate tickets? And is this one ready to rename and close for WP_Admin_Bar
?
Additional props: @audrasjb @SergeyBiryukov
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
18 months ago
#38
@
17 months ago
Can you please address the comments above?
Thanks for the ping, @oglekler!
Somehow I missed the message above. My apologies.
I will be happy to split this task into separate ones as soon as I have the opportunity (probably later this week).
I'm working on a patch for this issue.