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

Add method trap()->return() #46

Merged
merged 2 commits into from
Jan 28, 2024
Merged

Add method trap()->return() #46

merged 2 commits into from
Jan 28, 2024

Conversation

roxblnfk
Copy link
Member

@roxblnfk roxblnfk commented Jan 28, 2024

What was changed

Add method trap()->return()

    /**
     * Send the dump if possible and then return the dumped value immediately.
     *
     * @param int|string $key Position in the value sequence (0-based) or name of the named argument.
     *
     * ```php
     * trap(42)->return(); // 42
     * trap(count: 42, value: 90)->return('value'); // 90
     * trap(foo: 'bar')->return(0); // 'bar'
     * trap()->return(); // exception
     * ```
     */
    public function return(int|string $key = 0): mixed

Why?

Sometimes you have to dump the argument value, which is calculated and not stored in a variable. In such cases, you have to extract the code into a separate variable, which is not very convenient. It's easier to wrap the value with trap( <value> )->return().

Checklist

  • Tests
  • Documentation

@roxblnfk roxblnfk added this to the 1.4.x milestone Jan 28, 2024
@roxblnfk roxblnfk merged commit 8cf827d into master Jan 28, 2024
16 checks passed
@roxblnfk roxblnfk deleted the feature/trap-method-return branch January 28, 2024 18:25
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

Successfully merging this pull request may close these issues.

1 participant