Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85367 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36583 invoked from network); 21 Mar 2015 13:20:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Mar 2015 13:20:41 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.169 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.169 mail-we0-f169.google.com Received: from [74.125.82.169] ([74.125.82.169:34222] helo=mail-we0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/33-18917-8207D055 for ; Sat, 21 Mar 2015 08:20:41 -0500 Received: by wegp1 with SMTP id p1so102162824weg.1 for ; Sat, 21 Mar 2015 06:20:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=TNPdDCv+dHX3YlV5lK5sR008KuSdoec2PW5aKs6HMPA=; b=A0W6haMp7vqImTC75pCQJ51+h26UtJ8R6n5L2SDTHeLPfuVRRzYGMHp5tYz6QWyfat gOme9XcGdLm+hIzoLwKLiY0AHq+A8Zn90pAZtqX3kqGHsjb047eIOaBdd43WE8DMTbgA ARORogexZcP2WVBLBFjWS8xOg6DNOTSKCmZGL+XRLx82LRNZV/tTUhjULycrGY4oSQ5X HGbcO8u7SEWXToP1wtJ/wpqgtBiWB5L6rHM+/ID+ba5W8a5o1EoaX2KO8M5M0mXZS2fE ScZ22L0g8Qkk+THqsE9PNdfRIu+ymZPnnLf8+1un7iZ4etPrtfd8RR4AxfNyV74UvESz M5Gg== X-Gm-Message-State: ALoCoQmK4vKlXDKylOQgG/1CS0baGyXfiipciUX3FNjCnDSUuEjVurboE/eFTNNYBniXO2nBvc4J MIME-Version: 1.0 X-Received: by 10.194.239.65 with SMTP id vq1mr164126442wjc.98.1426944036668; Sat, 21 Mar 2015 06:20:36 -0700 (PDT) Received: by 10.194.36.134 with HTTP; Sat, 21 Mar 2015 06:20:36 -0700 (PDT) X-Originating-IP: [77.11.90.164] In-Reply-To: References: Date: Sat, 21 Mar 2015 14:20:36 +0100 Message-ID: To: "Georges.L" Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c1b8f06b9de50511cc4c7d Subject: Re: [PHP-DEV] RFC: Nested enclosing returns From: kontakt@beberlei.de (Benjamin Eberlei) --001a11c1b8f06b9de50511cc4c7d Content-Type: text/plain; charset=UTF-8 On Sat, Mar 21, 2015 at 1:13 PM, 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 > Hi Georges, In my opinion this is a bad idea. With break/continue/goto the jumps are restricted to only one function body to explicitly reduce the complexity in understanding them. With your proposal, as a user of a function I wouldn't know how deep a function returns. This can easily lead to extremely unexpected behavior. This is why exceptions are better for jumps up the call-stack, because they give the caller an explicit way of either accepting or catching the jump. > > > Regards, > Georges.L > --001a11c1b8f06b9de50511cc4c7d--