zephir icon indicating copy to clipboard operation
zephir copied to clipboard

Improvements to switch statement

Open dschissler opened this issue 5 years ago • 0 comments

Currently switch statements are overly picky about how they are setup and also in regards to method return types.

The compile will issue a warning about the "123" case because the break comes after the return. I like to put a break for 1) visual padding between cases, 2) it prevents accidental errors when refactoring from returning values in the switch and assigning to a variable instead.

First Annoyance

I can't do this without getting a compiler warning.

        switch value {
            case 123:
                return "abc";
                break;
            default:
                throw new \Exception("Invaid application runmode.");
        }

Second Annoyance

Return statements performed in a switch statement don't count towards satisfying a method return type.

These two issues can be worked around but they contribute to the unpleasantness of working with Zephir. I've learned to simply not do these things but I'd rather write the code the way that I want to.

dschissler avatar Nov 01 '18 02:11 dschissler