Skip to content

more precise preg_match types #11222

Closed
phpstan/phpstan-src
#3369

Description

@staabm

Feature request

while implementing the first iteration of preg_match array-shape inference, I got a few ideas on how the type inference could be improved.

leaving it here as a feature request, so its not forgotten

https://phpstan.org/r/1e3506dd-78dc-4bbe-9c9e-2a5a2928fcfc

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

No response

Activity

  1. ondrejmirtes commented on Jun 21, 2024

    @ondrejmirtes
    Member

    First thing we should is to cover preg_match_all and maybe others as well.

  2. phpstan-bot commented on Aug 1, 2024

    @phpstan-bot
    Contributor

    @staabm After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -10: Expected type array{string, '£'|'€'}, actual: array<string>
    -13: Expected type array{string, numeric-string}, actual: array<string>
    -16: Expected type array{string, non-empty-string}, actual: array<string>
    -19: Expected type array{string, non-empty-string}, actual: array<string>
    -22: Expected type array{string, non-falsey-string}, actual: array<string>
    +10: Expected type array{string, '£'|'€'}, actual: array{string, non-empty-string}
    +22: Expected type array{string, non-falsey-string}, actual: array{string, non-empty-string}
    Full report
    Line Error
    10 `Expected type array{string, '£'
    22 Expected type array{string, non-falsey-string}, actual: array{string, non-empty-string}
  3. phpstan-bot commented on Aug 5, 2024

    @phpstan-bot
    Contributor

    @staabm After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -10: Expected type array{string, '£'|'€'}, actual: array<string>
    -13: Expected type array{string, numeric-string}, actual: array<string>
    -16: Expected type array{string, non-empty-string}, actual: array<string>
    -19: Expected type array{string, non-empty-string}, actual: array<string>
    -22: Expected type array{string, non-falsey-string}, actual: array<string>
    +10: Expected type array{string, '£'|'€'}, actual: array{string, non-empty-string}
    +22: Expected type array{string, non-falsey-string}, actual: array{string, non-falsy-string}
    Full report
    Line Error
    10 `Expected type array{string, '£'
    22 Expected type array{string, non-falsey-string}, actual: array{string, non-falsy-string}
  4. github-actions commented on Sep 29, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  5. locked as resolved and limited conversation to collaborators on Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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