From 945e97eb1331a5f32d344cbfaf732af666d49d92 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Thu, 22 Oct 2026 13:57:13 +0100 Subject: [PATCH] Compare enum values as strings so a null value doesn't deprecate A case-insensitive EnumValidator passed the value straight to strcasecmp(), so validating a null value (an empty or missing field) raised PHP 8.1's "Passing null to parameter" deprecation. Both sides are now cast to string, which is what strcasecmp() did implicitly before. phpunit now converts deprecations to exceptions, and the unit tests run on PHP 7.4 and 8.2-8.5. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 4 ++-- .gitignore | 1 + phpunit.xml | 2 +- src/Validators/EnumValidator.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 54d12ff..507f898 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 7.4, 8.0 ] + php: [ '7.4', '8.2', '8.3', '8.4', '8.5' ] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 with: fetch-depth: 0 diff --git a/.gitignore b/.gitignore index c25d1dd..d81af83 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /composer.lock /node_modules/ /yarn.lock +/.phpunit.result.cache diff --git a/phpunit.xml b/phpunit.xml index 3d82334..b88555b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,7 +5,7 @@ colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" - convertWarningsToExceptions="true" + convertWarningsToExceptions="true" convertDeprecationsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="./vendor/autoload.php"> diff --git a/src/Validators/EnumValidator.php b/src/Validators/EnumValidator.php index ee1c4a9..47d84f2 100644 --- a/src/Validators/EnumValidator.php +++ b/src/Validators/EnumValidator.php @@ -75,7 +75,7 @@ protected function _doValidate($value): Generator $result = false; foreach($this->_getAllowedValues() as $allowedValue) { - if(strcasecmp($allowedValue, $value) == 0) + if(strcasecmp((string)$allowedValue, (string)$value) == 0) { $result = true; break;