Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48455 invoked from network); 22 Mar 2015 08:54:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2015 08:54:54 -0000 Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.41 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 209.85.213.41 mail-yh0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:33143] helo=mail-yh0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/C5-00828-D538E055 for ; Sun, 22 Mar 2015 03:54:53 -0500 Received: by yhpt93 with SMTP id t93so56673793yhp.0 for ; Sun, 22 Mar 2015 01:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=4O/P6iW/MO08QbuUk3sjH1yNYCdzN2sasevXRzygYOQ=; b=EpZ6OR3NLANIFxCBP+tO4UBYG/va7snUa3zDFq13A4aDPQMVqnR90bzdZyt/WYoCWN 1UxH5h9hmUyZ3flbbaUI3j5Lj3FRZToiLE1eWaUDx9/6qrgdFHQUAXG0NpiktrmfIEa0 8fdIAvAu8ZKxmlN+rTC9iF+IBS/6zhhV17YeHzsp4Xk1ZmQQ2l0+Tly4yzLKBTYUpkp/ AtlZLL+X4v1pyW+tbJemuSli66AGQ3ZAI7lLdHPe0t3CjnwDYPDVyr05I94BoBWyqi/Y C0Xe9IM4kpv96kMKP9W6mdBOQzddeO/ZPZPoW7g9PQ+rvtA9DO/RAJ/TtFQgAYcWIvkN qyNQ== MIME-Version: 1.0 X-Received: by 10.52.157.72 with SMTP id wk8mr403495vdb.12.1427014490585; Sun, 22 Mar 2015 01:54:50 -0700 (PDT) Received: by 10.52.177.7 with HTTP; Sun, 22 Mar 2015 01:54:50 -0700 (PDT) In-Reply-To: References: Date: Sun, 22 Mar 2015 08:54:50 +0000 Message-ID: To: "Georges.L" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=089e016338eeccfe4d0511dcb32d Subject: Re: [PHP-DEV] RFC: Nested enclosing returns From: leight@gmail.com (Leigh) --089e016338eeccfe4d0511dcb32d Content-Type: text/plain; charset=UTF-8 On 21 March 2015 at 12:13, Georges.L 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! --089e016338eeccfe4d0511dcb32d--