Skip to content

Allow 8.5 as PHP version no. 2 #4192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reflection-golden-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- uses: Wandalen/wretry.action@v3.8.0
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
operating-system: [ubuntu-latest, windows-latest]

steps:
Expand Down Expand Up @@ -80,6 +81,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
operating-system: [ ubuntu-latest, windows-latest ]

steps:
Expand Down
2 changes: 1 addition & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parameters:
bootstrapFiles:
- ../stubs/runtime/ReflectionUnionType.php
- ../stubs/runtime/ReflectionAttribute.php
- ../stubs/runtime/Attribute.php
- ../stubs/runtime/Attribute85.php
- ../stubs/runtime/ReflectionIntersectionType.php
excludePaths: []
level: null
Expand Down
6 changes: 3 additions & 3 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ parametersSchema:
buffer: int()
])
phpVersion: schema(anyOf(
schema(int(), min(70100), max(80499)),
schema(int(), min(70100), max(80599)),
structure([
min: schema(int(), min(70100), max(80499)),
max: schema(int(), min(70100), max(80499))
min: schema(int(), min(70100), max(80599)),
max: schema(int(), min(70100), max(80599))
])
), nullable())
polluteScopeWithLoopInitialAssignments: bool()
Expand Down
4 changes: 2 additions & 2 deletions e2e/composer-min-open-end-version/test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

\PHPStan\Testing\assertType('int<80100, 80499>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<80100, 80599>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<1, 4>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<1, 5>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
4 changes: 2 additions & 2 deletions e2e/composer-min-version/test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

\PHPStan\Testing\assertType('int<80100, 80499>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<80100, 80599>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('8', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<1, 4>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<1, 5>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
2 changes: 1 addition & 1 deletion e2e/composer-no-versions/test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

\PHPStan\Testing\assertType('int<50207, 80499>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<50207, 80599>', PHP_VERSION_ID);
\PHPStan\Testing\assertType('int<5, 8>', PHP_MAJOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_MINOR_VERSION);
\PHPStan\Testing\assertType('int<0, max>', PHP_RELEASE_VERSION);
2 changes: 1 addition & 1 deletion src/Php/PhpVersionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class PhpVersionFactory
{

public const MIN_PHP_VERSION = 70100;
public const MAX_PHP_VERSION = 80499;
public const MAX_PHP_VERSION = 80599;
public const MAX_PHP5_VERSION = 50699;
public const MAX_PHP7_VERSION = 70499;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use function extension_loaded;
use function is_dir;
use function is_file;
use const PHP_VERSION_ID;

#[AutowiredService]
final class BetterReflectionSourceLocatorFactory
Expand Down Expand Up @@ -75,7 +76,13 @@ public function __construct(

public function create(): SourceLocator
{
$locators = [];
$locators = [
$this->optimizedSingleFileSourceLocatorRepository->getOrCreate(
PHP_VERSION_ID < 80500
? __DIR__ . '/../../../stubs/runtime/Attribute84.php'
: __DIR__ . '/../../../stubs/runtime/Attribute85.php',
),
];

if ($this->singleReflectionFile !== null) {
$locators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($this->singleReflectionFile);
Expand Down
11 changes: 10 additions & 1 deletion src/Testing/TestCaseSourceLocatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
use PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator;
use ReflectionClass;
use function dirname;
use function is_file;
use function serialize;
use function sha1;
use const PHP_VERSION_ID;

final class TestCaseSourceLocatorFactory
{
Expand All @@ -35,6 +37,7 @@ final class TestCaseSourceLocatorFactory
*/
public function __construct(
private ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker,
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
private Parser $phpParser,
private Parser $php8Parser,
private FileNodesFetcher $fileNodesFetcher,
Expand All @@ -57,7 +60,13 @@ public function create(): SourceLocator
$this->excludePaths,
]));
if ($classLoaderReflection->hasProperty('vendorDir') && ! isset(self::$composerSourceLocatorsCache[$cacheKey])) {
$composerLocators = [];
$composerLocators = [
$this->optimizedSingleFileSourceLocatorRepository->getOrCreate(
PHP_VERSION_ID < 80500
? __DIR__ . '/../../stubs/runtime/Attribute84.php'
: __DIR__ . '/../../stubs/runtime/Attribute85.php',
),
];
$vendorDirProperty = $classLoaderReflection->getProperty('vendorDir');
$vendorDirProperty->setAccessible(true);
foreach ($classLoaders as $classLoader) {
Expand Down
File renamed without changes.
88 changes: 88 additions & 0 deletions stubs/runtime/Attribute85.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

if (\PHP_VERSION_ID < 80000 && !class_exists('Attribute', false)) {
#[Attribute(Attribute::TARGET_CLASS)]
class Attribute
{

/** @var int */
public $flags;

/**
* Marks that attribute declaration is allowed only in classes.
*/
const TARGET_CLASS = 1;

/**
* Marks that attribute declaration is allowed only in functions.
*/
const TARGET_FUNCTION = 1 << 1;

/**
* Marks that attribute declaration is allowed only in class methods.
*/
const TARGET_METHOD = 1 << 2;

/**
* Marks that attribute declaration is allowed only in class properties.
*/
const TARGET_PROPERTY = 1 << 3;

/**
* Marks that attribute declaration is allowed only in class constants.
*/
const TARGET_CLASS_CONSTANT = 1 << 4;

/**
* Marks that attribute declaration is allowed only in function or method parameters.
*/
const TARGET_PARAMETER = 1 << 5;

/**
* Marks that attribute declaration is allowed only in global constants with "const" keyword.
*/
const TARGET_CONSTANT = 1 << 6;

/**
* Marks that attribute declaration is allowed anywhere.
*/
const TARGET_ALL = (1 << 7) - 1;

/**
* Notes that an attribute declaration in the same place is
* allowed multiple times.
*/
const IS_REPEATABLE = 1 << 7;

/**
* @param int $flags A value in the form of a bitmask indicating the places
* where attributes can be defined.
*/
public function __construct($flags = self::TARGET_ALL)
{
$this->flags = $flags;
}

}
}

if (\PHP_VERSION_ID < 80100 && !class_exists('ReturnTypeWillChange', false)) {
#[Attribute(Attribute::TARGET_METHOD)]
final class ReturnTypeWillChange
{
}
}

if (\PHP_VERSION_ID < 80200 && !class_exists('AllowDynamicProperties', false)) {
#[Attribute(Attribute::TARGET_CLASS)]
final class AllowDynamicProperties
{
}
}

if (\PHP_VERSION_ID < 80200 && !class_exists('SensitiveParameter', false)) {
#[Attribute(Attribute::TARGET_PARAMETER)]
final class SensitiveParameter
{
}
}
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/ScopePhpVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public static function dataTestPhpVersion(): array
{
return [
[
'int<80000, 80499>',
'int<80000, 80599>',
__DIR__ . '/data/scope-constants-global.php',
],
[
'int<80000, 80499>',
'int<80000, 80599>',
__DIR__ . '/data/scope-constants-namespace.php',
],
];
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/predefined-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
assertType('int<5, 8>', PHP_MAJOR_VERSION);
assertType('int<0, max>', PHP_MINOR_VERSION);
assertType('int<0, max>', PHP_RELEASE_VERSION);
assertType('int<50207, 80499>', PHP_VERSION_ID);
assertType('int<50207, 80599>', PHP_VERSION_ID);
assertType('string', PHP_EXTRA_VERSION);
assertType('0|1', PHP_ZTS);
assertType('0|1', PHP_DEBUG);
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function dataParameters(): array
'bootstrapFiles' => [
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionUnionType.php'),
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionAttribute.php'),
realpath(__DIR__ . '/../../../stubs/runtime/Attribute.php'),
realpath(__DIR__ . '/../../../stubs/runtime/Attribute85.php'),
realpath(__DIR__ . '/../../../stubs/runtime/ReflectionIntersectionType.php'),
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'here.php',
],
Expand Down
10 changes: 8 additions & 2 deletions tests/PHPStan/Php/PhpVersionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ public static function dataCreate(): array
[
null,
'8.5',
80499,
'8.4.99',
80500,
'8.5',
],
[
null,
'8.0.95',
80095,
'8.0.95',
],
[
null,
'8.6',
80599,
'8.5.99',
],
];
}

Expand Down
Loading