Skip to content

Add Stubs for Magento's loosey-string behavior #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

navarr
Copy link

@navarr navarr commented Jul 11, 2025

In many cases, Magento typedefs a string but truly accepts anything that can be cast to a string. This can be annoying for things like Escaper and Session Messages, which many are inclined to pass Phrase objects into.

Additionally, Escaper has return types of string|array, passing an array if the input is an array. However, Magento's documentation blocks don't specify that's when it passes an array - so phpstan thinks that the result of Escaper can be either at any time. In that way, you cannot echo out the result of an escapeHtml in a PHTML file on max level without getting some errors.

Resolves #343

In many cases, Magento typedefs a `string` but truly accepts anything that can be cast to a string. This can be annoying for things like Escaper and Session Messages, which many are inclined to pass Phrase objects into.

Additionally, Escaper has return types of `string|array`, passing an array if the input is an array. However, Magento's documentation blocks don't specify that's when it passes an array - so phpstan thinks that the result of Escaper can be either at any time.  In that way, you cannot echo out the result of an `escapeHtml` in a PHTML file on max level without getting some errors.
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.

Feature Request: Stub for Escaper
1 participant