Skip to content

Add __unserialize() magic method to prevent PHP 8.5 deprecation warnings#9916

Closed
USERSATOSHI wants to merge 5 commits intoWordPress:trunkfrom
USERSATOSHI:try/fix-deprecation-warning-for-wakeup-method
Closed

Add __unserialize() magic method to prevent PHP 8.5 deprecation warnings#9916
USERSATOSHI wants to merge 5 commits intoWordPress:trunkfrom
USERSATOSHI:try/fix-deprecation-warning-for-wakeup-method

Conversation

@USERSATOSHI
Copy link
Copy Markdown

This PR adds __unserialize() implementations across WordPress core classes to address PHP 8.5 deprecation of __wakeup(). The new methods mirror existing __wakeup() behavior - either throwing LogicException for classes that shouldn't be unserialized, or performing validation/cleanup for classes that can be safely restored. __wakeup() methods are kept as wrappers calling the same logic as __unserialize().

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


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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 16, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props tusharbharti, swissspidy, dmsnell, tobiasbg.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@swissspidy
Copy link
Copy Markdown
Member

What's with the failing tests?

}

public function __wakeup() {
public function __unserialize( $data ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requests library needs to be fixed upstream first

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I checked the upstream issue on Request Library and this comment WordPress/Requests#949 (comment) mentioned that the fix is needed to be applied here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, for now, this should be fixed directly in Core. According to this comment, Requests 2.1.0 will fix the originally patched issue (which introduced the __wakeup call) differently, so that both the __wakeup and __unserialize can then be removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to change this old class AFAICT

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got it, I will remove for this file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This file has been fixed upstream, see https://core.trac.wordpress.org/ticket/64008.

@USERSATOSHI
Copy link
Copy Markdown
Author

What's with the failing tests?

checking the error it seems like src/wp-includes/Requests/src/Utility/FilteredIterator.php unserialize function has undefined $callback which it wasnt giving on wakeup

Copy link
Copy Markdown
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

Thanks for this update, I appreciate you keeping the __wakeup() methods for compatibility. From the HTML API perspective this looks fine.

// Do nothing.
}
} No newline at end of file
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These edits seem unrelated. If we have a problem with the no-op comment, that might be best addressed in a separate ticket. I suspect this is left-over from removing other edits, but the newline at the end and the comment changes are still here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

got it, I have discarded the changes.

@github-actions
Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60787
GitHub commit: 4b88704

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Sep 20, 2025
@TobiasBg
Copy link
Copy Markdown

This should please be reopened as it still contains changes that need to be committed.

@swissspidy swissspidy reopened this Sep 21, 2025
@github-actions
Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60796
GitHub commit: 2e3248f

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants