nerdexam
Adobe

AD0-E724 · Question #59

A developer needs to extend the functionality of a public method in a core Adobe Commerce class. They want to execute their custom code after the original method has run and modify its return value. W

The correct answer is C. 'after' plugin. An after plugin is correct because it runs after the original method completes and receives the method's return value as a parameter, allowing you to inspect or modify it before it's returned to the caller - exactly what the scenario requires. An around plugin could technically a

Customization

Question

A developer needs to extend the functionality of a public method in a core Adobe Commerce class. They want to execute their custom code after the original method has run and modify its return value. Which type of plugin (interceptor) should be used?

Options

  • A'around' plugin
  • B'instead' plugin
  • C'after' plugin
  • D'before' plugin

How the community answered

(42 responses)
  • A
    7% (3)
  • B
    2% (1)
  • C
    86% (36)
  • D
    5% (2)

Explanation

An after plugin is correct because it runs after the original method completes and receives the method's return value as a parameter, allowing you to inspect or modify it before it's returned to the caller - exactly what the scenario requires.

An around plugin could technically accomplish this too, but it's overkill: it wraps the entire method, requiring you to manually call $proceed() to invoke the original, which adds unnecessary complexity and fragility. There is no 'instead' plugin type in Adobe Commerce - it simply doesn't exist as a valid interceptor. A before plugin runs prior to the original method and can only modify input arguments, not the return value, so it can't fulfill this requirement.

Memory tip: Match the timing word to the task - after = "after it ran, touch the result"; before = "before it runs, touch the arguments"; around = "you control everything, use sparingly."

Topics

#plugin#interceptor#after plugin#dependency injection

Community Discussion

No community discussion yet for this question.

Full AD0-E724 Practice