Skip to content

LatteTags: Fix PHPStan error with nette/forms < 3.3#21

Open
jtojnar wants to merge 9 commits into
nextras:masterfrom
jtojnar:duck-fix
Open

LatteTags: Fix PHPStan error with nette/forms < 3.3#21
jtojnar wants to merge 9 commits into
nextras:masterfrom
jtojnar:duck-fix

Conversation

@jtojnar

@jtojnar jtojnar commented Jul 14, 2026

Copy link
Copy Markdown
Contributor
  • phpstan: Ignore temp files
  • LatteTags: Fix PHPStan error with nette/forms < 3.3

@hrach

hrach commented Jul 14, 2026

Copy link
Copy Markdown
Member

I'm totally ok with dropping PHP 8.0.

jtojnar added 7 commits July 14, 2026 08:50
PHPStan 2 would raise `argument.type` error:

    Parameter nextras#2 $haystack of function in_array expects array, mixed given.
It should still work but PHPStan would get angry:

    Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
    Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
    Error: Parameter nextras#1 $object_or_class of function method_exists expects object|string, mixed given.
    Error: Cannot call method getLabelPrototype() on class-string|object.
    Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
    Error: Parameter nextras#1 $object_or_class of function method_exists expects object|string, mixed given.
    Error: Cannot call method getControlPrototype() on class-string|object.
    Error: Cannot call method getControlPrototype() on class-string|object.
    Error: Cannot call method getLabelPrototype() on class-string|object.

Likely because on PHP 8.0 we need to use `nette/forms` 3.1.15 rather than 3.2.9 used by PHP 8.1, and the former uses PHPDoc instead of property type hints:

https://github.com/nette/forms/blob/v3.1.15/src/Forms/Rendering/DefaultFormRenderer.php#L121

And we do not want to bother fixing it.
This will satisfy PHPStan 2.

While it is not guaranteed that the methods will return `Html`,
any reasonable control implementation probably does that.
`phpstan/phpstan-nette` registers `PropertyReflection` for `Html` class that changes property types to `mixed`:

https://github.com/phpstan/phpstan-nette/blob/2.0.12/src/Reflection/Nette/HtmlPropertyReflection.php#L21

This seems to take precedence over the upstream `@property` PHPDoc annotations:

nette/utils@52d7e1b

As a result, PHPStan would complain:

    Parameter nextras#1 $child of method Nette\Utils\Html::addHtml() expects Nette\HtmlStringable|string, mixed given.
Similarly to in previous commit, `phpstan/phpstan-nette` changes virtual property types to `mixed`. As a result, PHPStan would complain:

    Binary operation "." between mixed and '-inline' results in an error.
PHPStan 2 will consider the `property_exists` check always true so we need to ignore it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants