Skip to content

DOM stubbed properties not working #8837

@hemberger

Description

@hemberger

Bug report

Perhaps I am misunderstanding how stubs work, but the stubbed class properties in https://github.com/phpstan/phpstan-src/blob/1.10.x/stubs/dom.stub do not appear to be working. For example, given:

class DOMDocument {
    /** @var null */
    public $ownerDocument;
}

class DOMElement {
    /** @var DOMDocument */
    public $ownerDocument;
}

I did not expect that when I inspect $document->ownerDocument or $element->ownerDocument, both are inferred as DOMDocument|null.

For the class methods, the return types do appear to be inferred according to the stubs.

Code snippet that reproduces the problem

https://phpstan.org/r/df249433-544c-44f4-915d-7702f00c66ca

Expected output

4 | Dumped type: DOMDocument
7 | Dumped type: null

That is, for $element->ownerDocument, I expect DOMDocument, and for $document->ownerDocument, I expect null.

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

Yes, it helps every day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions