Skip to content

ValidatorIE uses deprecated string increment operator on PHP 8.3+ #158

Description

@PhilETaylor

Problem

ValidatorIE::validateIENew() uses the ++ operator on a string variable ($checkChar++ on line 79) to walk the alphabet. Since PHP 8.3, incrementing a non-numeric string with ++ is deprecated and triggers:

Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead

This happens when validating Irish VAT numbers where the checksum character is not W (i.e., $checkVal is greater than 0).

Stack trace:

ValidatorIE.php:79 in validateIENew()
ValidatorIE.php:35 in validate()
Vies.php:389 in validateVatSum()
Vies.php:310 in validateVat()

Affected code

// src/Vies/Validator/ValidatorIE.php, lines 77-80
$checkChar = 'A';
for ($i = $checkVal - 1; $i > 0; $i--) {
    $checkChar++;
}

Suggested fix

Replace the loop with chr() arithmetic:

$checkChar = chr(ord('A') + $checkVal - 1);

This works on all PHP versions and eliminates the loop entirely.

Environment

  • PHP 8.4
  • dragonbe/vies 2.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions