Skip to content

fix(diagnostics): declare $cleanDiagnostics property - #136

Open
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/126-php83-dynamic-property-clean-diagnostics
Open

fix(diagnostics): declare $cleanDiagnostics property#136
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/126-php83-dynamic-property-clean-diagnostics

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Fixes the PHP 8.3 deprecation notice emitted on every diagnostic AJAX request: Deprecated: Creation of dynamic property PostmanGetDiagnosticsViaAjax::$cleanDiagnostics is deprecated. The class assigned to the property in its constructor without declaring it, so PHP 8.3 flags it and PHP 8.4 would escalate it to a fatal error.
\nFixes #126

Changes

Postman/Postman-Diagnostic-Test/PostmanDiagnosticTestController.php

Before:

class PostmanGetDiagnosticsViaAjax {
    private $diagnostics;
    private $options;
    private $authorizationToken;

After:

class PostmanGetDiagnosticsViaAjax {
    private $diagnostics;
    private $cleanDiagnostics;
    private $options;
    private $authorizationToken;

Why: The constructor at line 170 assigns $this->cleanDiagnostics = ''; without a matching declaration, so every call creates the property dynamically. Adding the declaration next to its siblings silences the deprecation without changing behaviour. All existing usage at lines 170, 176, and 348 still works.

Testing

PHP 8.3 + WP_DEBUG

  1. Install Post SMTP 3.3.0 with PHP 8.3, WP 6.8.1, and WP_DEBUG=true WP_DEBUG_LOG=true.
  2. Before applying the fix: trigger the diagnostic test from wp-admin and confirm wp-content/debug.log contains the "Creation of dynamic property" deprecation line.
  3. Apply the fix and repeat step 2.
  4. Result: the deprecation entry no longer appears, and the post_smtp_clean_diagnostic_report_data option is still populated with the diagnostic text as before.
    \nTested manually against a WordPress 6.8.1 install on PHP 8.3.

Fixes PHP 8.3 'Creation of dynamic property' deprecation warning
emitted by the diagnostic AJAX class on every WP_DEBUG request.

PHP 8.3 deprecates assigning to an undeclared class property;
PHP 8.4 escalates the same notice to a fatal error. The class
already declared three siblings at the top of the file but
$cleanDiagnostics was only assigned in the constructor, leaving
the rest of the file (line 176, line 348) to rely on the implicit
dynamic property.

Adding the declaration next to its siblings silences the warning
with no behaviour change.

Fixes wpexpertsio#126
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.

1 participant