0

Like I have this function

public function letsTry(){
 $this->callFuncion($name1, $name2, true);
}

private function callFunction($arg1, $arg2, $arg3 = false){
  // do stuff
}

How i can change the 3rd parameter true to false using plugin or remove it. Or i need to use preference for this?

0

yes it's possible we can change output value or any other param value using plugin but make sure you are using plugin on public function because plugin only work on public class not on end classes. if you want to change param value before executing function then you can use "Before Plugin" if you want to change param value or output value then you should you "After plugin" and if you want to do modification during function execution then you can use "Around plugin".

you can use blow links as reference for how plugin works:

Magento 2 After plugin with parameter
How plugin work

If you find this answer useful then upvote this answers. Thanks

  • Doesn't answer the question – Kingshuk Deb Feb 12 at 12:42
-1

You can use before plugin

public function beforecallFunction(\Vendor\Module\Your\Class$subject, $arg1, $arg2, $arg3)
    {
        return [ $arg1,$arg2,false];
    }

Update: You cannot apply plugins to Non-public methods so this will not work

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.