Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to alter a parameter before using Patchwork\pass() or before Patchwork\callOriginal()? #25

Open
tomolimo opened this issue Apr 13, 2015 · 1 comment

Comments

@tomolimo
Copy link

The idea is to have the possibility to alter a parameter before calling the original method.
I found this working:

public static function patchworkMyFunction($type, $options) {
        if( $type == 3 ) {
            $param = Patchwork\Stack\top('args');
            $param[1]=-1;
        }
        return Patchwork\callOriginal();
    }

But not this

public static function patchworkMyFunction($type, $options) {
        if( $type == 3 ) {
            $options=-1;
        }
        return Patchwork\callOriginal();
    }

And not this:

public static function patchworkMyFunction($type, $options) {
        if( $type == 3 ) {
            $param = Patchwork\Stack\top('args');
            $param[1]=-1;
        }
        Patchwork\pass();
    }

Could you advise or comment?
Thank you,
Regards,
Tomolimo

@antecedent
Copy link
Owner

Hello,
I'm sure you have figured this one out by now, but for the future reference of other users, this can be done by passing an argument array to callOriginal:

public static function patchworkMyFunction($type, $options) {
        return Patchwork\callOriginal([-1, $options]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants