From a4f65fadf92fd5de8cde96b7088302af7c3f1c7b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 12 Dec 2025 14:44:18 +0100 Subject: [PATCH 1/4] Constants deprecation depends on Scope->getPhpVersion() --- .../FetchingDeprecatedConstRuleTest.php | 17 ++++++++++++++++ tests/Rules/Deprecations/data/bug-162.php | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/Rules/Deprecations/data/bug-162.php diff --git a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php index 1428ec2..b16ff74 100644 --- a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php +++ b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php @@ -59,4 +59,21 @@ public function testFetchingDeprecatedConst(): void ); } + public function testEstrictWithVersionGuard(): void + { + require_once __DIR__ . '/data/bug-162.php'; + $this->analyse( + [__DIR__ . '/data/bug-162.php'], + [ + [ + 'Use of constant E_STRICT is deprecated.', + 7 + ], + [ + 'Use of constant E_STRICT is deprecated.', + 18 + ], + ], + ); + } } diff --git a/tests/Rules/Deprecations/data/bug-162.php b/tests/Rules/Deprecations/data/bug-162.php new file mode 100644 index 0000000..2bc64e5 --- /dev/null +++ b/tests/Rules/Deprecations/data/bug-162.php @@ -0,0 +1,20 @@ += 80400) { + if (E_STRICT === $errno) { + + } + } + + if (PHP_VERSION_ID < 80400) { + if (E_STRICT === $errno) { + + } + } + + if (E_STRICT === $errno ) { + } +} From 462e22252fcb465885e57969dc18d77fce02ea16 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 12 Dec 2025 14:46:15 +0100 Subject: [PATCH 2/4] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e378f4..1d54697 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^2.1.15" + "phpstan/phpstan": "^2.1.34" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", From 14e2d9eb5851fda8a3d7f588eefb797f8d8d5ffc Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 12 Dec 2025 14:46:46 +0100 Subject: [PATCH 3/4] Update FetchingDeprecatedConstRuleTest.php --- tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php index b16ff74..2bfaf8c 100644 --- a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php +++ b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php @@ -67,13 +67,14 @@ public function testEstrictWithVersionGuard(): void [ [ 'Use of constant E_STRICT is deprecated.', - 7 + 7, ], [ 'Use of constant E_STRICT is deprecated.', - 18 + 18, ], ], ); } + } From 9aca5db10378110aebba3848fb711afd93889c6e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 12 Dec 2025 14:49:30 +0100 Subject: [PATCH 4/4] expectations are version dependent --- .../FetchingDeprecatedConstRuleTest.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php index 2bfaf8c..c09f8f6 100644 --- a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php +++ b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use function defined; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -61,10 +62,14 @@ public function testFetchingDeprecatedConst(): void public function testEstrictWithVersionGuard(): void { - require_once __DIR__ . '/data/bug-162.php'; - $this->analyse( - [__DIR__ . '/data/bug-162.php'], + $errors = [ [ + 'Use of constant E_STRICT is deprecated.', + 7, + ], + ]; + if (PHP_VERSION_ID >= 80400) { + $errors = [ [ 'Use of constant E_STRICT is deprecated.', 7, @@ -73,7 +78,13 @@ public function testEstrictWithVersionGuard(): void 'Use of constant E_STRICT is deprecated.', 18, ], - ], + ]; + } + + require_once __DIR__ . '/data/bug-162.php'; + $this->analyse( + [__DIR__ . '/data/bug-162.php'], + $errors, ); }