Skip to content

Commit 3f140ed

Browse files
committed
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
1 parent 24a5991 commit 3f140ed

6 files changed

Lines changed: 12 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
php: ['8.1', '8.2', '8.3', '8.4']
22+
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
2323

2424
steps:
2525
- name: Checkout

packages/logtide/src/Integration/ErrorListenerIntegration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ public function teardown(): void
6262

6363
private static function severityToLevel(int $severity): LogLevel
6464
{
65+
// E_STRICT is intentionally absent: the level was removed in PHP 8.0 and
66+
// the constant itself is deprecated since 8.4, so referencing it here
67+
// would emit a deprecation from inside the error handler.
6568
return match (true) {
6669
(bool) ($severity & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)) => LogLevel::CRITICAL,
6770
(bool) ($severity & (E_WARNING | E_CORE_WARNING | E_COMPILE_WARNING | E_USER_WARNING | E_RECOVERABLE_ERROR)) => LogLevel::WARN,
68-
(bool) ($severity & (E_NOTICE | E_USER_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED)) => LogLevel::INFO,
71+
(bool) ($severity & (E_NOTICE | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED)) => LogLevel::INFO,
6972
default => LogLevel::ERROR,
7073
};
7174
}

packages/logtide/src/Serializer/ErrorSerializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ public static function serializePhpError(int $severity, string $message, string
6565

6666
private static function errorLevelToString(int $level): string
6767
{
68+
// E_STRICT is intentionally absent: the level was removed in PHP 8.0 and
69+
// the constant itself is deprecated since 8.4, so referencing it here
70+
// would emit a deprecation from inside the error handler.
6871
return match ($level) {
6972
E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR => 'E_ERROR',
7073
E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING => 'E_WARNING',
7174
E_NOTICE, E_USER_NOTICE => 'E_NOTICE',
72-
E_STRICT => 'E_STRICT',
7375
E_DEPRECATED, E_USER_DEPRECATED => 'E_DEPRECATED',
7476
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
7577
default => 'E_UNKNOWN',

packages/logtide/tests/Unit/Serializer/ErrorSerializerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public function testErrorLevelMapping(): void
8282
$this->assertSame('E_WARNING', ErrorSerializer::serializePhpError(E_WARNING, '', '', 0)['type']);
8383
$this->assertSame('E_NOTICE', ErrorSerializer::serializePhpError(E_NOTICE, '', '', 0)['type']);
8484
$this->assertSame('E_DEPRECATED', ErrorSerializer::serializePhpError(E_DEPRECATED, '', '', 0)['type']);
85-
$this->assertSame('E_STRICT', ErrorSerializer::serializePhpError(E_STRICT, '', '', 0)['type']);
85+
$this->assertSame('E_DEPRECATED', ErrorSerializer::serializePhpError(E_USER_DEPRECATED, '', '', 0)['type']);
86+
$this->assertSame('E_RECOVERABLE_ERROR', ErrorSerializer::serializePhpError(E_RECOVERABLE_ERROR, '', '', 0)['type']);
87+
$this->assertSame('E_UNKNOWN', ErrorSerializer::serializePhpError(0, '', '', 0)['type']);
8688
}
8789
}

packages/logtide/tests/Unit/State/ScopeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class ScopeTest extends TestCase
1818
protected function tearDown(): void
1919
{
2020
$ref = new \ReflectionProperty(Scope::class, 'globalEventProcessors');
21-
$ref->setAccessible(true);
2221
$ref->setValue(null, []);
2322
}
2423

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
colors="true"
66
failOnRisky="true"
77
failOnWarning="true"
8+
failOnDeprecation="true"
89
displayDetailsOnTestsThatTriggerDeprecations="true">
910
<testsuites>
1011
<testsuite name="Core">

0 commit comments

Comments
 (0)