givewp icon indicating copy to clipboard operation
givewp copied to clipboard

More PHP 8.2+ deprecation notices

Open flack opened this issue 2 months ago • 2 comments

similar to #7141. I have checked again with WP_DEBUG_DISPLAY = true and the latest Give release. Here is a list of notices that get displayed on almost every page:

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\Donation::$donorInfo is deprecated in src/Session/SessionDonation/SessionObjects/Donation.php on line 122

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$honeypot is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$formIdPrefix is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$formUrl is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$formMinimum is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$formMaximum is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$formHash is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\FormEntry::$paymentMode is deprecated in src/Session/SessionDonation/SessionObjects/FormEntry.php on line 125

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\Donation::$cardInfo is deprecated in src/Session/SessionDonation/SessionObjects/Donation.php on line 122

Creation of dynamic property Give\Session\SessionDonation\SessionObjects\Donation::$donorInfo is deprecated in src/Session/SessionDonation/SessionObjects/Donation.php on line 122

Automatic conversion of false to array is deprecated in includes/payments/actions.php on line 400

explode(): Passing null to parameter #2 ($string) of type string is deprecated in includes/class-give-donor.php on line 1625

Return type of MyCLabs\Enum\Enum::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/myclabs/php-enum/src/Enum.php on line 246

Just on the backend start page (/wp-admin/), there are more than 50 such notices I have to scroll past to get to the content. This makes it very hard to debug and write clean code. From what I can tell, most problems can be fixed by simply using the AllowDynamicProperties annotation on the FormEntry and Donation classes in SessionObjects.

flack avatar Mar 25 '24 10:03 flack

I can get rid of most of the notices by applying this diff:

diff --git a/wp-content/plugins/give/includes/payments/actions.php b/wp-content/plugins/give/includes/payments/actions.php
index 7cc64e11a..f5ed2320f 100644
--- a/wp-content/plugins/give/includes/payments/actions.php
+++ b/wp-content/plugins/give/includes/payments/actions.php
@@ -362,7 +362,7 @@ function give_bc_v20_get_payment_meta( $check, $object_id, $meta_key, $single )
 		// User ID.
 		$donor_data['id'] = $donation->user_id;
 
-		$donor_data['address'] = false;
+		$donor_data['address'] = [];
 
 		// Address1.
 		$address1 = ! empty( $payment_meta['_give_donor_billing_address1'] ) ? $payment_meta['_give_donor_billing_address1'] : '';
@@ -400,6 +400,10 @@ function give_bc_v20_get_payment_meta( $check, $object_id, $meta_key, $single )
 			$donor_data['address']['country'] = $country;
 		}
 
+		if (empty($donor_data['address'])) {
+		    $donor_data['address'] = false;
+		}
+
 		$payment_meta['user_info'] = $donor_data;
 
 		// Add filter
diff --git a/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/Donation.php b/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/Donation.php
index 9d28a3405..452d64f63 100644
--- a/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/Donation.php
+++ b/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/Donation.php
@@ -23,6 +23,7 @@ use Give\ValueObjects\ValueObjects;
  * @property FormEntry $formEntry
  * @property DonorInfo $donorInfo
  */
+#[\AllowDynamicProperties]
 class Donation implements Objects
 {
     /**
diff --git a/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/FormEntry.php b/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/FormEntry.php
index 57721ba5f..f65e6814c 100644
--- a/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/FormEntry.php
+++ b/wp-content/plugins/give/src/Session/SessionDonation/SessionObjects/FormEntry.php
@@ -13,6 +13,7 @@ use Give\Session\Objects;
  *
  * @package Give\Session\SessionDonation\SessionObjects
  */
+#[\AllowDynamicProperties]
 class FormEntry implements Objects
 {
     /**
diff --git a/wp-content/plugins/give/vendor/myclabs/php-enum/src/Enum.php b/wp-content/plugins/give/vendor/myclabs/php-enum/src/Enum.php
index b8b93277e..18829bd8c 100644
--- a/wp-content/plugins/give/vendor/myclabs/php-enum/src/Enum.php
+++ b/wp-content/plugins/give/vendor/myclabs/php-enum/src/Enum.php
@@ -243,6 +243,7 @@ abstract class Enum implements \JsonSerializable
      * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
      * @psalm-pure
      */
+    #[\ReturnTypeWillChange]
     public function jsonSerialize()
     {
         return $this->getValue();

flack avatar Mar 25 '24 10:03 flack

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 14 additional days. Note, if this Issue is reporting a bug, please reach out to our support at https://givewp.com/support. If this is a feature request, please see our feedback board at feedback.givewp.com — that’s the best place to make feature requests, unless you’re providing a PR.

github-actions[bot] avatar May 10 '24 01:05 github-actions[bot]