Skip to content

spurious error in specific combination of namespace blocks and function declaration with phpdoc type annotation #13831

Closed

Description

@claudepache

Bug report

I encountered a strange spurious PHPStan error in the following setting:

// Any non-global namespace block ...
namespace foo {
	// ...
}

// ... followed by a global namespace block ...
namespace {

   // ... and a function declaration here with completed type information in phpdoc
    // will trigger the spurious error:

    /** @return list<string> */
    function qux(): array {   // <-- ??? `missingType.iterableValue` error
        return [ random_bytes(16) ];
    }
	
    \PHPStan\dumpType(qux()); // ok: list<string>
}

(If you are curious: I encountered this issue in my stub file, and I’ve worked around it by reordering the namespace blocks.)

Code snippet that reproduces the problem

https://phpstan.org/r/c714d401-a96b-4e88-b0c8-8ad956180e61

Expected output

No error on line 15.

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

No response

Activity

  1. changed the title [-]spurious error in specific combination of namespace blocks and function declaration with doctype[/-] [+]spurious error in specific combination of namespace blocks and function declaration with phpdoc type annotation[/+] on Nov 20, 2025
  2. added this to the Easy fixes milestone on Feb 9, 2026
  3. phpstan-bot commented on Feb 27, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    -15: Function qux() return type has no value type specified in iterable type array.
     19: Dumped type: list<string>
    Full report
    Line Error
    19 Dumped type: list<string>
  4. claudepache commented on Mar 1, 2026

    @claudepache
    Author
  5. github-actions commented on Apr 2, 2026

    @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.

  6. locked as resolved and limited conversation to collaborators on Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions