Skip to content

more precise Superglobals / readonlySuperglobals #8037

Open

Description

@staabm

Feature request

in psalm with vimeo/psalm#8473 recently more precise Superglobals were added.
I am thinking about doing the same for phpstan behind a readonlySuperglobals feature flag.

in tandem I would implement a new Rule which errors when code modifies one of the superglobal arrays.
(so we can "prevent" people writing types into a superglobal which don't fit the intended types)

https://phpstan.org/r/e99e22a3-014d-4edf-85ed-969857a34af5

wdyt?

Activity

  1. mvorisek commented on Jun 7, 2023

    @mvorisek
    Contributor

    Yes, for example $_GET can be only string or array of strings.

  2. phpstan-bot commented on Jun 9, 2023

    @phpstan-bot
    Collaborator

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

    @@ @@
    - 7: Dumped type: array<string, mixed>
    - 8: Dumped type: array<string, mixed>
    - 9: Dumped type: array<string, mixed>
    -10: Dumped type: array<string, mixed>
    -11: Dumped type: array<string, mixed>
    -12: Dumped type: array<string, mixed>
    -13: Dumped type: array<string, mixed>
    -14: Dumped type: array<string, mixed>
    + 7: Dumped type: array
    + 8: Dumped type: array
    + 9: Dumped type: array
    +10: Dumped type: array
    +11: Dumped type: array
    +12: Dumped type: array
    +13: Dumped type: array
    +14: Dumped type: array
    Full report
    Line Error
    7 Dumped type: array
    8 Dumped type: array
    9 Dumped type: array
    10 Dumped type: array
    11 Dumped type: array
    12 Dumped type: array
    13 Dumped type: array
    14 Dumped type: array
  3. phpstan-bot commented on Oct 12, 2024

    @phpstan-bot
    Collaborator

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

    @@ @@
    - 7: Dumped type: array<string, mixed>
    - 8: Dumped type: array<string, mixed>
    - 9: Dumped type: array<string, mixed>
    -10: Dumped type: array<string, mixed>
    -11: Dumped type: array<string, mixed>
    -12: Dumped type: array<string, mixed>
    -13: Dumped type: array<string, mixed>
    -14: Dumped type: array<string, mixed>
    + 7: Dumped type: array<mixed>
    + 8: Dumped type: array<mixed>
    + 9: Dumped type: array<mixed>
    +10: Dumped type: array<mixed>
    +11: Dumped type: array<mixed>
    +12: Dumped type: array<mixed>
    +13: Dumped type: array<mixed>
    +14: Dumped type: array<mixed>
    Full report
    Line Error
    7 Dumped type: array<mixed>
    8 Dumped type: array<mixed>
    9 Dumped type: array<mixed>
    10 Dumped type: array<mixed>
    11 Dumped type: array<mixed>
    12 Dumped type: array<mixed>
    13 Dumped type: array<mixed>
    14 Dumped type: array<mixed>
  4. westonruter commented on Oct 27, 2026

    @westonruter
    Contributor

    I've opened a PR for this: phpstan/phpstan-src#6866

    This would be very useful for analyzing WordPress core which uses superglobals extensively.

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