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

Fix PHP 8.2 deprecation warning #759

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DanieleAlessandra
Copy link
Collaborator

@DanieleAlessandra DanieleAlessandra commented Nov 11, 2024

The report on PHP 8.2 deprecation warnings for dynamic properties highlighted three cases, which this PR addresses:

  1. FS_Plugin_Plan::pricing – This was resolved in June.
  2. FS_Site::blog_id – This issue was due to direct assignment.
  3. FS_User::is_beta – This resulted from the use of unserialize.

Changes:

  • Removed the @property FS_Pricing[] $pricing annotation from FS_Plugin_Plan, as the property now exists and the annotation is no longer necessary.
  • Added the $blog_id property to FS_Site and removed the corresponding annotation, similar to the previous class.
  • Introduced the __wakeup magic method to FS_User to remove deprecated properties from serialized entities.
  • Added the __unserialize magic method to FS_User to manage the result of unserialize and prevent warnings. This method only works with public properties and can be removed if the __wakeup method is sufficient. __unserialize magic method is detected as non-magic in PHP 7.3 and older by phpcs.

@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/fix-deprecation-warning-with-php8.2 branch from 2724729 to 452e982 Compare November 11, 2024 18:05
* Should clean up the serialized data to avoid PHP 8.2 warning on next execution.
*/
public function __wakeup() {
if ( isset($this->is_beta) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DanieleAlessandra What if is_beta is null?

@@ -48,6 +48,19 @@ function __construct( $user = false ) {
parent::__construct( $user );
}

/**
* @return void
Copy link
Contributor

Choose a reason for hiding this comment

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

@DanieleAlessandra I think this should be after the description.

* This function removes the deprecated 'is_beta' property from the serialized data.
* Should clean up the serialized data to avoid PHP 8.2 warning on next execution.
*/
public function __wakeup() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DanieleAlessandra When the method is public, there's no need to include public.

/**
* @return void
*
* This function removes the deprecated 'is_beta' property from the serialized data.
Copy link
Contributor

@fajardoleo fajardoleo Nov 27, 2024

Choose a reason for hiding this comment

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

@DanieleAlessandra Please use "method" instead of "function".

class FS_Site extends FS_Scope_Entity {
/**
* @var number
*/
public $site_id;
/**
* @var number
Copy link
Contributor

@fajardoleo fajardoleo Nov 27, 2024

Choose a reason for hiding this comment

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

@DanieleAlessandra This should be int like in the get_unfiltered_site_url() method (also consistent with the annotation you removed). For entity IDs though, we use number (like in the FS_Entity class).

@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/fix-deprecation-warning-with-php8.2 branch 2 times, most recently from 64b9641 to 93d2d11 Compare December 2, 2024 17:40
@DanieleAlessandra
Copy link
Collaborator Author

This PR needs to be removed, cannot merge directly to master

@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/fix-deprecation-warning-with-php8.2 branch 2 times, most recently from 88730e2 to f8429f2 Compare December 3, 2024 16:42
…ion warning adding missing property to FS_Site class and using magic functions in FS_User class. FS_Plugin_Plan has been fixed in June.

[User Entity] Removed magic method __unserialize for backward compatibility with PHP 7.3 and older

Removing FS_User::$is_beta dynamic created property with obsolete data from database
@DanieleAlessandra DanieleAlessandra force-pushed the feature/daniele/fix-deprecation-warning-with-php8.2 branch from f8429f2 to cfa06e3 Compare December 3, 2024 16:44
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.

2 participants