Skip to content

Improve isOffsetAccessible->no #8393

@rajyan

Description

@rajyan

Feature request

https://3v4l.org/b3Vem
As we can see here, there are two types of isOffsetAccessible->no. Whether it throws a fatal error in isset/coalesce/empty ($scope->isUndefinedExpressionAllowed) or not.
I think we can improve NonexistentOffsetInArrayDimFetchRule by separating these.

Also, a lot of people are not aware why StrictMixedType throws an error with the code below, maybe we can add some information in the document

/** @var mixed $mixed */
isset($mixed['foo']);

Goal

https://phpstan.org/r/1087a148-ae5b-477f-9003-215fefc3437f
No error in line 7, 21
Throw error in 12

Design

  • Add method something like isOffsetAccessThrowsFatalError(): TernaryLogic (want a better naming...) to Types
  • Return TernaryLogic::Yes for isOffsetAccessThrowsFatalError in MixedType/StrictMixedType if object type is subtracted

Related issues

These issues should be closed after documented

The test should be reverted after this is implemented

Array access with json_decode mixed problems

Did PHPStan help you today? Did it make you happy in any way?

PHPStan on PHPStan finds error while developing PHPStan 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions