Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110118 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63468 invoked from network); 10 May 2020 21:36:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 May 2020 21:36:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C98161804C8 for ; Sun, 10 May 2020 13:12:25 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 May 2020 13:12:25 -0700 (PDT) Received: by mail-wr1-f66.google.com with SMTP id l11so2456058wru.0 for ; Sun, 10 May 2020 13:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=c7ihxGIFd4aF0Z0yIDUukcP6vd/ilJCzHOEeC05UV6Y=; b=efhpu6ujXiVDhZANgowFhRhZSRqq+Ry32csuFTmwHX2k78K3DPNMmlr3mQ9NTHEpOg N2FT4T7sPKuDxW1RSkm4pHFJKcJ09IJEsemJP9yDrZsSj2mxGWNsyNobFiqz+3fe3Mgp 4+eKNaQqkPBx7E9X/7xBLH5q4P86XnK2N+iYGeO/35/N3came/UrhKo0+5dqmDIkxA0V pRRZ3M8oT0MNaHMzyHyevdBqdlh9RkMLe/w63gXv4JuX2jZqh43b/DoGGam/GuXZvZ6O +ypCn6ib7FirLZRIdQnYSKxTiRtXbmSrFGfUTOHI266DXexy87YSe0a1VtFPvKBBQ4f4 ZX4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=c7ihxGIFd4aF0Z0yIDUukcP6vd/ilJCzHOEeC05UV6Y=; b=cpR/N3vC8TkgCt65LIIGAypO+1e4w6wGvAvaRZtTWZm+xt6T6jb3KU5lYN6qi7XzgT TuYAJwjRZk07tS8NPnmu/NJ3yC8fVb5rf7iSg8cOLU22YKdK3PTe3bIwiLV5rX0/sFF7 Onc/pfLk6kqm/lQLBGOmAJujpgVjlCgYHyJZ5KEamH0ih6pmxcNDQTgPqyMI8r5WiEFA 7VaMnDMFdGeP+SFLlZcSaUIQ7AyMP231DFGY67uTvCTPyl7BnelAQlIBZ5yGasuwAv96 ULOwv8Lk26KT4WybYuK/dPcoNcL0fgFRjmuZwXizg2BfM5XsqtwNxYrtGZCo2yDyCjuW my0Q== X-Gm-Message-State: AGi0PuZd1qMsh543vpFFc26XfXoJS/ecJBCVBlaefo/sUGm3FFjskrig yx8f47rcPLorhtC6KU3sLgm3D8g9 X-Google-Smtp-Source: APiQypJyyRhVxM11PjCfbvbTpBDgpHX89odClaxVXGIK9yeRy/a9SlZceCyX9LcZw47YxpcGdlUmHw== X-Received: by 2002:adf:edc1:: with SMTP id v1mr14601479wro.125.1589141541275; Sun, 10 May 2020 13:12:21 -0700 (PDT) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id r2sm15755792wrg.84.2020.05.10.13.12.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 May 2020 13:12:20 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <549cb6b7-f4f1-686a-0ea4-bf853afb03d3@gmail.com> Date: Sun, 10 May 2020 21:12:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Proposal For Return-If / Early Return / Guard Clause Syntax From: rowan.collins@gmail.com (Rowan Tommins) Hi Ralph, Like others, I think this feels too narrow in its scope, and doesn't add enough over existing syntax. You mention that Ruby has a similar feature, but there it's not a special syntax for guard clauses per se, but a "modifier" form of the if statement: https://docs.ruby-lang.org/en/2.7.0/syntax/control_expressions_rdoc.html#label-Modifier+if+and+unless Along with "unless" (an alias for "if not"), it's supposed to let you write more sentence-like code: print "Hat Trick!" if $goals == 3; throw new BadInputException unless is_valid($input); In fact, Ruby also has modifier forms of while and until; and Perl (where I think this all came from) also for and foreach. I'm not sure whether I'd welcome that syntax in PHP or not, but it would be one way to allow the throw, break, etc cases that other people have mentioned in addition to return, rather than having to invent special syntaxes for each. Regards, -- Rowan Tommins (né Collins) [IMSoP]