Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85369 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43361 invoked from network); 21 Mar 2015 14:18:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Mar 2015 14:18:23 -0000 Authentication-Results: pb1.pair.com header.from=contact@geolim4.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=contact@geolim4.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain geolim4.com designates 212.129.18.216 as permitted sender) X-PHP-List-Original-Sender: contact@geolim4.com X-Host-Fingerprint: 212.129.18.216 houblon.geolim4.com Received: from [212.129.18.216] ([212.129.18.216:33672] helo=houblon.geolim4.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4C/44-18917-DAD7D055 for ; Sat, 21 Mar 2015 09:18:22 -0500 Received: from mail-qg0-f51.google.com (mail-qg0-f51.google.com [209.85.192.51]) (Authenticated sender: contact@geolim4.com) by houblon.geolim4.com (Postfix) with ESMTPSA id 7CECDEC0029 for ; Sat, 21 Mar 2015 15:18:17 +0100 (CET) Received: by qgez102 with SMTP id z102so25798194qge.3 for ; Sat, 21 Mar 2015 07:18:16 -0700 (PDT) X-Received: by 10.55.40.9 with SMTP id o9mr142817647qkh.55.1426947496256; Sat, 21 Mar 2015 07:18:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.90.36 with HTTP; Sat, 21 Mar 2015 07:17:46 -0700 (PDT) In-Reply-To: References: Date: Sat, 21 Mar 2015 15:17:46 +0100 Message-ID: To: Benjamin Eberlei Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114412bca0ae780511cd1a87 Subject: Re: [PHP-DEV] RFC: Nested enclosing returns From: contact@geolim4.com ("Georges.L") --001a114412bca0ae780511cd1a87 Content-Type: text/plain; charset=UTF-8 The main purpose of this RFC is *not* to improve the exception system of PHP but to improve the code logic/hierarchy. Using this like loop (for/foreach etc.) you can skip a lot of parent callers for a desired purpose by example. I agree with you in the sens were this can complicate significantly the debug/trace process, but IMO, there's more benefits than inconvenience. Also I agree with you too, were it can lead in a sort of "spaghetti code" feature (like Goto operator is...), but which language is not a bit "spaghetti" today? But my request is not to have a fully dynamic nested return, but a "controlled" dynamic nested return. I would not see this to be improved: return $something, $nesting_level; If I remember that feature has been removed in continue/break as of php 5.4, so this isn't that hard, right? :) Georges.L 2015-03-21 14:20 GMT+01:00 Benjamin Eberlei : > > > 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 >> > > --001a114412bca0ae780511cd1a87--