Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 4, 2025

Closes phpstan/phpstan#13592

We will still need an option to report array key cast, especially for boolean keys.

Partially solves phpstan/phpstan#7864

@VincentLanglet VincentLanglet force-pushed the deprecateNullAndFloatOffset branch 3 times, most recently from 6b9f23d to cd4e33c Compare October 4, 2025 11:41
@VincentLanglet VincentLanglet force-pushed the deprecateNullAndFloatOffset branch from cd4e33c to 456c943 Compare October 4, 2025 11:43
@VincentLanglet VincentLanglet marked this pull request as ready for review October 4, 2025 11:53
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

namespace InvalidKeyArrayDimFetch;

$a = [];
$foo = $a[null];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved PHP-related errors to the end for an easier handling in tests.

$a[true];
$a[false];

/** @var string|null $stringOrNull */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed for a valid union here and move the invalid string|null to the end

@VincentLanglet
Copy link
Contributor Author

BaselineNeonErrorFormatterIntegrationTest::testErrorWithTrait failure seems unrelated and doesn't fail locally.

{

public static function getType(): Type
public static function getType(?PhpVersion $phpVersion = null): Type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why optional and nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in ArrayType and ConstantArrayType

$allowedArrayKeys = AllowedArrayKeysTypes::getType();

and I don't have a PHPVersion here


public function __construct(
private RuleLevelHelper $ruleLevelHelper,
private PhpVersion $phpVersion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More modern approach is to get PhpVersions from Scope (a separate class).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it means that all the method from PhpVersion should be deprecated/moved into PhpVersions ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet

@ondrejmirtes ondrejmirtes merged commit 71f7b78 into phpstan:2.1.x Oct 6, 2025
542 of 551 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report using null as array offset

3 participants