1

About use of each kind of interceptor (plugin) was answered here: Is it better to use solely around function instead of before+after combined? But in Magento docs says:

Avoid using around method plugins when they are not required because they increase stack traces and affect performance

With that in mind... I know in some cases we must use it because is the only way, but when it is possible to use before and after instead around should I always do it? Before and after together have better performance than around?

In my case for example, I just want to test if a plugin changed a Object that is not received as parameter, so in beforeMethod I would get its object status and check if was modified in afterMethod. Should I use before+after or around?

Update Magento docs answer this question somehow:

The only use case for around method plugins is when the execution of all further plugins and original methods need termination

0

"Using the Around plugin in your code isn’t the best practice. Magento recommends avoiding this method and using the before and after plugins instead." - Amasty

So use After and before but if you want to completely override the public method then you can use around that is why it gets introduced to us right.

but it might cause issues in the future. So Avoid it as much you can

2
  • Which kind of issue you mean? – jefferson Mar 28 at 18:41
  • I think this might prevent execution of code. If anything is mis match or not properly handle or any changes done to that method in future. – Nilesh Dubey Mar 28 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.