Skip to content

Extra arguments passed to getChildren() cause inconsistent plugin behavior #40257

@mohammadbharmal

Description

@mohammadbharmal

Summary

Preconditions:

  • Magento Open Source 2.4.x (verified on 2.4.7 and 2.4-develop)
  • Clean installation, no custom overrides required

Steps to Reproduce:

  1. Review \Magento\Catalog\Model\Category where getChildren() is called:

$this->getResource()->getChildren($this, $recursive, $isActive, $sortByPosition);

  1. Open \Magento\Catalog\Model\ResourceModel\Category and observe the method signature:
public function getChildren($category, $recursive = true)
{
    ...
}
  1. Notice that only 2 parameters are defined in the resource model, but 4 are being passed.

  2. Generated interceptors include:

public function getChildren($category, $recursive = true)
{
    $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getChildren');
    return $pluginInfo
        ? $this->___callPlugins('getChildren', func_get_args(), $pluginInfo)
        : parent::getChildren($category, $recursive);
}
  1. Create a plugin for getChildren() that uses $proceed() — observe argument mismatches or confusion about expected parameters.

Expected Result:

Method signatures between model and resource model should align, or Documentation (PHPDoc / comment) should clarify that extra parameters are intentionally passed for backward compatibility.

Plugin developers should not face uncertainty about argument counts.

Actual Result:

  • 4 parameters are passed while only 2 are defined.
  • The interceptor passes all via func_get_args(), which can, confuse plugin developers, produce argument mismatches when $proceed() is used, /and reduce IDE/static analysis accuracy.

Examples

  1. Review \Magento\Catalog\Model\Category where getChildren() is called:

$this->getResource()->getChildren($this, $recursive, $isActive, $sortByPosition);

  1. Open \Magento\Catalog\Model\ResourceModel\Category and observe the method signature:
public function getChildren($category, $recursive = true)
{
    ...
}

Proposed solution

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Issue: needs updateAdditional information is require, waiting for responseReported on 2.4.7Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Needs Update

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions