magento / magento/magento-coding-standard

Replacing `$this` with `$block` in templates is not universally safe / correct

Open
#407 5 comments 2 reactions 1 assignee View on GitHub

@fredden is already working on this.

Since Jul 7, 2022.

bug Progress: PR created
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

Preconditions
  1. In a template (.phtml file), make use of $this->helper(SomeClass:class);. For example, https://github.com/magento/magento2/blob/2.4.4/app/code/Magento/Catalog/view/frontend/templates/product/listing.phtml#L20
  2. Magento Coding Standard version 25
Steps to reproduce
  1. Run phpcbf --standard=Magento2 on template
Expected result
  1. Template works the same as before auto-fixes are applied.
Actual result
  1. Exception is throw: Invalid method Vendor\Module\Block\SomeBlockClass\Interceptor::helper

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.