From 3f140edd5f78c246c495ed307545ec3cc765dbda Mon Sep 17 00:00:00 2001 From: Polliog <40077351+Polliog@users.noreply.github.com> Date: Fri, 21 Aug 2026 15:59:32 +0200 Subject: [PATCH] fix E_STRICT deprecation notices on php 8.4 and 8.5 E_STRICT was referenced in two spots on the error handling path: ErrorListenerIntegration::severityToLevel() and ErrorSerializer::errorLevelToString(). Both match arms are evaluated lazily, so the constant was only touched for notice and deprecation level diagnostics, which is why every app notice produced two extra 'Constant E_STRICT is deprecated' lines. Those lines were printed by php itself instead of being captured, since php does not re-enter the user error handler while it is already running. The level was removed back in php 8.0 and this package requires ^8.1, so both arms were dead code already. In php 9.0 the constant is gone entirely, which would have thrown Undefined constant inside the error handler. Also drops a ReflectionProperty::setAccessible() call deprecated in 8.5, adds failOnDeprecation to phpunit.xml so this class of issue breaks the build instead of passing silently, and adds 8.5 to the CI matrix. Fixes #7 --- .github/workflows/ci.yml | 2 +- .../logtide/src/Integration/ErrorListenerIntegration.php | 5 ++++- packages/logtide/src/Serializer/ErrorSerializer.php | 4 +++- .../logtide/tests/Unit/Serializer/ErrorSerializerTest.php | 4 +++- packages/logtide/tests/Unit/State/ScopeTest.php | 1 - phpunit.xml | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb21ad1..e712290 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3', '8.4'] + php: ['8.1', '8.2', '8.3', '8.4', '8.5'] steps: - name: Checkout diff --git a/packages/logtide/src/Integration/ErrorListenerIntegration.php b/packages/logtide/src/Integration/ErrorListenerIntegration.php index 179f5d9..dd9541f 100644 --- a/packages/logtide/src/Integration/ErrorListenerIntegration.php +++ b/packages/logtide/src/Integration/ErrorListenerIntegration.php @@ -62,10 +62,13 @@ public function teardown(): void private static function severityToLevel(int $severity): LogLevel { + // E_STRICT is intentionally absent: the level was removed in PHP 8.0 and + // the constant itself is deprecated since 8.4, so referencing it here + // would emit a deprecation from inside the error handler. return match (true) { (bool) ($severity & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)) => LogLevel::CRITICAL, (bool) ($severity & (E_WARNING | E_CORE_WARNING | E_COMPILE_WARNING | E_USER_WARNING | E_RECOVERABLE_ERROR)) => LogLevel::WARN, - (bool) ($severity & (E_NOTICE | E_USER_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED)) => LogLevel::INFO, + (bool) ($severity & (E_NOTICE | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED)) => LogLevel::INFO, default => LogLevel::ERROR, }; } diff --git a/packages/logtide/src/Serializer/ErrorSerializer.php b/packages/logtide/src/Serializer/ErrorSerializer.php index 017df33..a9a9ed4 100644 --- a/packages/logtide/src/Serializer/ErrorSerializer.php +++ b/packages/logtide/src/Serializer/ErrorSerializer.php @@ -65,11 +65,13 @@ public static function serializePhpError(int $severity, string $message, string private static function errorLevelToString(int $level): string { + // E_STRICT is intentionally absent: the level was removed in PHP 8.0 and + // the constant itself is deprecated since 8.4, so referencing it here + // would emit a deprecation from inside the error handler. return match ($level) { E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR => 'E_ERROR', E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING => 'E_WARNING', E_NOTICE, E_USER_NOTICE => 'E_NOTICE', - E_STRICT => 'E_STRICT', E_DEPRECATED, E_USER_DEPRECATED => 'E_DEPRECATED', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', default => 'E_UNKNOWN', diff --git a/packages/logtide/tests/Unit/Serializer/ErrorSerializerTest.php b/packages/logtide/tests/Unit/Serializer/ErrorSerializerTest.php index c709b37..fa6d88b 100644 --- a/packages/logtide/tests/Unit/Serializer/ErrorSerializerTest.php +++ b/packages/logtide/tests/Unit/Serializer/ErrorSerializerTest.php @@ -82,6 +82,8 @@ public function testErrorLevelMapping(): void $this->assertSame('E_WARNING', ErrorSerializer::serializePhpError(E_WARNING, '', '', 0)['type']); $this->assertSame('E_NOTICE', ErrorSerializer::serializePhpError(E_NOTICE, '', '', 0)['type']); $this->assertSame('E_DEPRECATED', ErrorSerializer::serializePhpError(E_DEPRECATED, '', '', 0)['type']); - $this->assertSame('E_STRICT', ErrorSerializer::serializePhpError(E_STRICT, '', '', 0)['type']); + $this->assertSame('E_DEPRECATED', ErrorSerializer::serializePhpError(E_USER_DEPRECATED, '', '', 0)['type']); + $this->assertSame('E_RECOVERABLE_ERROR', ErrorSerializer::serializePhpError(E_RECOVERABLE_ERROR, '', '', 0)['type']); + $this->assertSame('E_UNKNOWN', ErrorSerializer::serializePhpError(0, '', '', 0)['type']); } } diff --git a/packages/logtide/tests/Unit/State/ScopeTest.php b/packages/logtide/tests/Unit/State/ScopeTest.php index 7d91191..477b8de 100644 --- a/packages/logtide/tests/Unit/State/ScopeTest.php +++ b/packages/logtide/tests/Unit/State/ScopeTest.php @@ -18,7 +18,6 @@ final class ScopeTest extends TestCase protected function tearDown(): void { $ref = new \ReflectionProperty(Scope::class, 'globalEventProcessors'); - $ref->setAccessible(true); $ref->setValue(null, []); } diff --git a/phpunit.xml b/phpunit.xml index 98d4626..2d9cefd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,6 +5,7 @@ colors="true" failOnRisky="true" failOnWarning="true" + failOnDeprecation="true" displayDetailsOnTestsThatTriggerDeprecations="true">