đ§ M Bytes #14: Why Magento around() plugins increase call stack size
Published 2 days ago âĸ 1 min read
|
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,
|
|
|
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.
|
|
|
Did you like this edition of M Bytes? |
|
|
|
|
|
|