profile

M Bytes

🟧 M Bytes #14: Why Magento around() plugins increase call stack size


by M.academy​

Hey Reader,

I hope you've had a chance to play around with Magento 2.4.8 this last week or so (if not, check out my What's New in Magento video to learn all about it).

This week, we're learning all about plugins. If you've been a bit stumped about plugins (also known as "interceptors"), you can check out the new short Magento plugins playlist to dive in.

There are also links to some of the new video lessons below 👇

Keep coding,

Mark Shust

Teacher / M.academy

Say hi 👋 on LinkedIn & YouTube​

Create an after plugin in Magento

It's never OK to modify core code, and usually not a good idea to directly modify third-party code. Instead, consider using plugins, like after():

Create a before plugin in Magento

Oftentimes you may not need an after plugin; before() is its less-invasive sibling which let's you modify just the arguments of the original function:

The Unexpected Behavior of Magento Plugin Execution Order

Did you know that there is a weird/awkward execution order of around plugins?

Here's a complete breakdown of how before, after, and around plugins are executed — and it's not what you'd expect:

Did you know that around() creates a new execution context?

This is why the size of the call stack increases when adding around() plugins to your custom Magento code — and a reason why they should be avoided.

Disable a plugin in Magento

It's possible that a module has a custom plugin that is overriding core code — but maybe you don't want it to run? Rather than deleting it, consider disabling:

Spending too much time searching for answers?

University students jump straight to solutions with Maggie Bolt's instant help (just upgraded to GPT 4.1), detailed video-based courses, and Campus — our active developer community.

​

M.academy​
8940 Sassafras Cir, N. Royalton, OH 44133

​Remove me from M Bytes, remove me from everything or manage your profile​

M Bytes

Watch. Read. Apply. One topic every week.

Share this page