On 21 March 2015 at 12:13, Georges.L <cont...@geolim4.com> wrote:

> Hi php internals,
>
> After some long and deep research i finally decided to write my first RFC
> about a feature i'd be interested to be improved in the php core: *Nested
> enclosing returns*
>
>
> The main purpose, as the title say, is to have the possibility to nest
> multiple return like we can do currently with break/continue.
>
> I thinks it'll being better with a scheme:
>
>
>
>
> function foo($foo = true)
> {
>    if(!$foo)
>    {
>       return false, 3;// Please note the second return argument is the
> return nesting level
>    }
>    else
>    {
>       return true;// Default nested return argument is always equal to
> 1 (if not specified, current)
>    }
> }
>
> function bar($foo = true)
> {
>    foo($foo);
>    // Some stuff that will never be executed if $foo == false and
> nested return argument = 2
>    echo 'Hi jon !';
> }
>
> function baz($foo = true)
> {
>    echo 'Hi bertie !';
>    foo($foo);
>    // Some stuff that will never be executed if $foo == false and
> nested return argument = 3
>    echo 'Hi freddy !';
> }
>
>
> baz(true);  // Display:
>          //  Hi bertie !
>          //  Hi jon !
>          //  Hi freddy !
>
> baz(false);  // Display:
>          //  Hi bertie !
>
>
> Benefits:
> -Wont break compatibility
> -May improve code interpretation speed due to part of code skipped by the
> nested return.
> -Allow "dynamic" return expressions.
>
> Inconveniences:
> -May complicate debug/backtrace
>

I think this will lead to a debugging nightmare, sorry.

It allows functions to behave in an incredibly non-obvious way, makes it
really easy to break things, and when something is broken the complexity of
locating and fixing it feels like it will be insane.

I'm imagining functions with branches that have different return levels in
them, called from functions with branches with different return levels in
them.... I feel like crying and it's not even a real feature yet!

Reply via email to