Skip to content

PHP Deprecation: Creation of dynamic properties #127

@smartstak

Description

@smartstak

Bug Report

Describe the current, buggy behavior

Running the wp export command on PHP 8.2 or higher triggers a deprecation notice because the class WP_Post_IDs_Iterator creates a dynamic property $db, which is deprecated in PHP 8.2+. This message appears every time the export command is executed.

Describe how other contributors can replicate this bug

  • Install PHP 8.2 or PHP 8.3
  • Install WP-CLI (or use LocalWP which bundles WP-CLI)
  • Run:
wp export --post_type=job_listing
  • Observe the PHP deprecation warning regarding dynamic property creation.

Describe what you would expect as the correct outcome

The export command should run without any PHP deprecation warnings.

The class should not rely on dynamic properties and should define $db explicitly or use the recommended #[AllowDynamicProperties] attribute.

Let us know what environment you are running this on

  • Install PHP 8.2 or PHP 8.3
  • Install WP-CLI (or use LocalWP which bundles WP-CLI)
OS:     Windows NT 10.0 build 22621 (Windows 11) AMD64
Shell:  C:\Windows\system32\cmd.exe
PHP binary:     C:\Users\PCD\AppData\Roaming\Local\lightning-services\php-8.2.23+0\bin\win64\php.exe
PHP version:    8.2.23
php.ini used:   C:\Users\PCD\AppData\Roaming\Local\run\fjyitlrCC\conf\php\php.ini
MySQL binary:
MySQL version:
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       phar://C:/Program Files (x86)/Local/resources/extraResources/bin/wp-cli/wp-cli.phar
WP-CLI packages dir:
WP-CLI cache dir:       C:\Users\PCD/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.12.0

Provide a possible solution

  1. Explicitly declare the $db, $index_in_results, $global_index property inside WP_Post_IDs_Iterator, or
  2. Add the PHP 8.2-compatible attribute:
#[\AllowDynamicProperties]
class WP_Post_IDs_Iterator implements Iterator {

Provide additional context/Screenshots

This issue appears inside:

wp-cli/export-command/blob/main/src/WP_Post_IDs_Iterator.php

The bug affects all PHP 8.2+ environments and all tools that rely on WP-CLI for export operations, including LocalWP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions