Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82701 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64360 invoked from network); 14 Feb 2015 21:09:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2015 21:09:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:33049] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/C3-41866-399BFD45 for ; Sat, 14 Feb 2015 16:09:40 -0500 Received: by mail-wg0-f48.google.com with SMTP id l18so19719558wgh.7 for ; Sat, 14 Feb 2015 13:09:37 -0800 (PST) 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=4Gg7Sm2BtM7chV919wINLuGr2D7MkZhgkjMLN42fynM=; b=FLaC4TrxQ3S8M5H8IPQUSKcCOyZPjB2jnzhgIoU33An+3lYBoJx0P9BVifmkihh9vl dhI6WLm0suRCTD4gzj2xnhsmXmDn9v/6iIIrjV8PKGK1sXqDS0UNq40XIs76eOUL2G+u qFWQ1hG6bpejh4fruqVd65R2ErWj0L1srSN52tEqjXn4AzD/OK6zyhZKeC+EUUE983Pi Xvxah7eTLRtGtwJYKgT17nD65D9CPIrU22xB3t6wF031ks0FkCXE0QAhcWPvKITxQda9 7k9laRF/xZ60bN+54qwZtqlWHRtwPA/0tJp1NAxCD5yzQy8CgceO+OZagZ40uMKOHPl3 xtjw== MIME-Version: 1.0 X-Received: by 10.180.79.131 with SMTP id j3mr21225261wix.33.1423948176808; Sat, 14 Feb 2015 13:09:36 -0800 (PST) Received: by 10.27.10.168 with HTTP; Sat, 14 Feb 2015 13:09:36 -0800 (PST) In-Reply-To: References: <680FB44D-B42D-4898-A28B-FA1C6E4D4D1A@ajf.me> Date: Sat, 14 Feb 2015 22:09:36 +0100 Message-ID: To: Xinchen Hui Cc: Andrea Faulds , PHP Internals Content-Type: multipart/alternative; boundary=f46d044288ce41e0c6050f12c5fe Subject: Re: [PHP-DEV] [RFC] Void Return Type From: nikita.ppv@gmail.com (Nikita Popov) --f46d044288ce41e0c6050f12c5fe Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, Feb 14, 2015 at 6:03 AM, Xinchen Hui wrote: > Hey: > > > > On Sat, Feb 14, 2015 at 11:18 AM, Andrea Faulds wrote: > > Hi everyone, > > > > I=E2=80=99ve written a small RFC and patch to add a =E2=80=9Cvoid=E2=80= =9D return type: > > > > https://wiki.php.net/rfc/void_return_type > > > > Please have a read over it. I think this would be a simple, yet useful > addition. > be honest, I think it's only part of the idea is implemented. > > which make it useless. > > in PHP, even if you don't return anything, NULL is returned implicitly. > > even if a function is declared return nothing(void). > > like: > > function a() : void {}; > > following codes still works: > > $b =3D a(); > > so, if you want a void return type, and if you want it to be a useful > feature.. > > above expr should be invalid with an error " a() return nothing" > > so, I am -1 on this in complete RFC > Hi Xinchen! While doing something like $b =3D a() where a() is a void function does not make sense usually (and e.g. C will generate a warning/error for this) in PHP there are some cases where you would want to use the return value of a void function. Namely those are cases where you aren't calling a specific function, but a callback that can return anything instead. E.g. consider something like a partial application helper: function bind($fn, ...$bindArgs) { return function(...$args) use($fn) { return $fn(...$bindArgs, ...$args); }; } Right now this would work no matter how $fn is declared. However if you disallow using the return value of void functions, you'd have to create an extra bindVoid() function which does exactly the same thing, just without the "return". As such I don't think we can reasonably forbid using the return value of a void function. The utility of the "void" return type in PHP would be self-documenting function signatures. An IDE (or other static analyzer) would of course detect cases where the return value of a void function is used. Nikita --f46d044288ce41e0c6050f12c5fe--