Skip to content

Fix PHP 8.6 deprecation for class constant named namespace - #3191

Open
faisalahammad wants to merge 1 commit into
Automattic:trunkfrom
faisalahammad:fix/php86-rest-namespace-constant
Open

faisalahammad wants to merge 1 commit into
Automattic:trunkfrom
faisalahammad:fix/php86-rest-namespace-constant

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Changes Proposed in this Pull Request

  • PHP 8.6 deprecates using namespace as a class constant name, and the check is case-insensitive. Two REST classes declare private const NAMESPACE, so every request on PHP 8.6 logs:
    PHP Deprecated:  Declaring class constant called 'namespace' is deprecated in .../includes/helper/class-wp-job-manager-helper-rest-api.php on line 29
    PHP Deprecated:  Declaring class constant called 'namespace' is deprecated in .../includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php on line 20
    
  • Renamed the constant to REST_NAMESPACE in WP_Job_Manager_Helper_REST_API and WP_Job_Manager_Promoted_Jobs_API, and updated every use. The value stays wpjm-internal/v1, so routes do not change. The constant is private, so no outside code depends on the old name.

Testing Instructions

  1. On PHP 8.6, run php -l includes/helper/class-wp-job-manager-helper-rest-api.php on trunk. It shows the deprecation above.
  2. Switch to this branch and run it again, plus the same for includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php. No deprecation.
  3. With WP_DEBUG_LOG on, load any page and check debug.log. No Declaring class constant called 'namespace' line.
  4. Logged in as admin, open /wp-json/wpjm-internal/v1. It still lists the /promoted-jobs and /licensing/receive-wpcom-license-key routes.

PHPUnit (1257 tests) and PHPCS pass locally.

Release Notes

  • Fix PHP 8.6 deprecation notice for a class constant named namespace.

This branch has not been deployed

No deployments
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