Skip to content

Spoofchecker::setRestrictionLevel() error message suggests missing constants #20426

Closed

Description

@DanielEScherzer

Description

The following code:

<?php

try {
    (new Spoofchecker())->setRestrictionLevel( -2 );
} catch ( \Throwable $e ) {
    // Show the error message
    echo $e->getMessage() . "\n\n";
}

$cases = [
    'Spoofchecker::ASCII',
    'Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE',
    'Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE',
    'Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE',
    'Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE',
    'Spoofchecker::UNRESTRICTIVE',
];
foreach ( $cases as $case ) {
    if ( defined( $case ) ) {
        echo "$case - is defined\n";
    } else {
        echo "$case - NOT defined\n";
    }
}

Resulted in this output:

Spoofchecker::setRestrictionLevel(): Argument #1 ($level) must be one of Spoofchecker::ASCII, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE, Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE, Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE, or Spoofchecker::UNRESTRICTIVE

Spoofchecker::ASCII - is defined
Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE - is defined
Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE - NOT defined
Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE - NOT defined
Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE - NOT defined
Spoofchecker::UNRESTRICTIVE - is defined

But I expected this output instead:

  • ValueError message only suggests class constants that exist

PHP Version

8.3+

Operating System

No response

Activity

  1. DanielEScherzer commented on Nov 8, 2025

    @DanielEScherzer
    MemberAuthor

    Presumably the fix is

    • SINGLE_HIGHLY_RESTRICTIVE -> HIGHLY_RESTRICTIVE
    • SINGLE_MODERATELY_RESTRICTIVE -> MODERATELY_RESTRICTIVE
    • SINGLE_MINIMALLY_RESTRICTIVE -> MINIMALLY_RESTRICTIVE

    Tested with https://3v4l.org/Gg9r9

    The question is just what version of PHP should the fix be sent to - 8.3 or master? I'm happy to do the actual work

  2. devnexen commented on Nov 8, 2025

    @devnexen
    Member

    yes you would need to update the exception message in 8.3

  3. added 2 commits that reference this issue on Dec 1, 2025
    1e6e0d8
    c343ede
  4. added 3 commits that reference this issue on Dec 1, 2025
    355d296
    aa795a6
    b9e0445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions