Skip to content

Incorrect behavior of DowngradeHashAlgorithmXxHashRector when PHP version is checked #9327

Description

@kkmuffme

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/8a4b4765-e93f-463c-a784-a00d573197a6

<?php

final class DemoFile
{
    public function run()
    {
        return PHP_VERSION_ID >= 80100 ? hash( 'xxh128', $value ) : hash( 'md4', $value );
    }
    
    public function run_v()
    {
        return version_compare( PHP_VERSION, '8.1', '>=' ) ? hash( 'xxh128', $value ) : hash( 'md4', $value );
    }
}

Same also when not used with a ternary but regular if

    public function run_v()
    {
        if ( version_compare( PHP_VERSION, '8.1', '>=' ) ) {
            return hash( 'xxh128', $value );
        }
        
        return hash( 'md4', $value );
    }

Responsible rules

  • DowngradeHashAlgorithmXxHashRector

Expected Behavior

If there is a version check with PHP_VERSION_ID or PHP_VERSION it should not modify the code, since this is correct.

In addition, I'd say that also PHP_MAJOR_VERSION > 8 should not be changed for anything that downgrades below 8.0

I guess this issue not only affects this specific rule, but all downgrade rules

Activity

  1. samsonasik commented on Aug 25, 2025

    @samsonasik
    Member
  2. github-actions commented on Jan 25, 2026

    @github-actions
    Contributor

    This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

  3. locked as resolved and limited conversation to collaborators on Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions