Skip to content

Deprecated: Constant MHASH_XXH32 is deprecated since PHP8.5 #9825

Description

@mbilykov

Environment

  • Rector: 2.5.8 (latest as of 2026-07-27)
  • PHP: 8.5.8 (CLI)
  • OS: Linux (Docker, php:8.5-cli based image)

Bug description

Since PHP 8.5, the legacy MHASH_* constants (mhash extension) are deprecated
(php/php-src#16569 — the constants were overlooked when mhash_*() functions
were deprecated in PHP 8.1).

DowngradeHashAlgorithmXxHashRector references these constants in a class
constant array, which triggers a E_DEPRECATED notice the moment the class
is loaded / its constants are evaluated — even when the rule never matches
any code in the analyzed project. On PHP 8.5 this producing a wall of noise on
every rector process invocation.

Steps to reproduce

  1. Use PHP 8.5 as CLI.
  2. Run vendor/bin/rector process <path> with any config that includes the
    PHP 8.1 downgrade set (withDowngradeSets(php81: true) or any lower
    target, e.g. php74).
  3. Observe repeated deprecation notices in stdout.

Actual output

Deprecated: Constant MHASH_XXH32 is deprecated since 8.5, as the mhash*() functions were deprecated in vendor/rector/rector/vendor/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php on line 35
(repeated for MHASH_XXH64, MHASH_XXH3, MHASH_XXH128, each x2)

Expected behavior

No deprecation notices from Rector's own internals on PHP 8.5.

Root cause

rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php, line 35:

private const HASH_ALGORITHMS_TO_DOWNGRADE = [
    'xxh32'  => \MHASH_XXH32,
    'xxh64'  => \MHASH_XXH64,
    'xxh3'   => \MHASH_XXH3,
    'xxh128' => \MHASH_XXH128,
];
These MHASH_* int values are only used internally as unique sentinel
values for array_search() (line ~143, mapConstantToString()) — the rule
maps hash()'s string algo name to/from a constant-fetch AST node. The
actual mhash extension values are irrelevant here; only uniqueness
matters. There is no dependency on the real mhash constant value anywhere
in this rule.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions