Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82687 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22697 invoked from network); 14 Feb 2015 14:52:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2015 14:52:22 -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 209.85.212.179 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.179 mail-wi0-f179.google.com Received: from [209.85.212.179] ([209.85.212.179:45044] helo=mail-wi0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/B2-03565-5216FD45 for ; Sat, 14 Feb 2015 09:52:22 -0500 Received: by mail-wi0-f179.google.com with SMTP id hi2so17924005wib.0 for ; Sat, 14 Feb 2015 06:52:18 -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=SwjVyxXAy2XX9CIGCNScVSdLSJKt5pxWQKL9t94K9LM=; b=YbL2cnayWxAjEgPXW4nBEsH8dSSfQ9kkJAMZSiFcl7PImzUfdb6zjKAA14n2WO72Gp 4S8wEclEWaXSU82kVjUTWcEgpOurjg23qC/W/N7XWvHKHCnPdtp9D/gRzyr0c2fezG/H w7oUfOEmLO6vfpoX4dg5Q8RCbqwi9pNvhLHGIw5C9dkadwAUIVB+Ah2ZPFPK8z6XatqD Xo2r9KM07d+q6wMUoveRhV/qeCEmVwv8fMv9w6QnxTtT9vKW703jEwgO3bJKfC00FvXT ohgSldt3urUFxYx1V9bRpbect1i1ZWSvhOES/7xX+Q/W1KVwdpexQ4MD8leCK8ASzkXP t3OQ== MIME-Version: 1.0 X-Received: by 10.195.12.71 with SMTP id eo7mr16312661wjd.3.1423925538382; Sat, 14 Feb 2015 06:52:18 -0800 (PST) Received: by 10.27.10.168 with HTTP; Sat, 14 Feb 2015 06:52:18 -0800 (PST) In-Reply-To: <54DF5B79.6050009@gmail.com> References: <680FB44D-B42D-4898-A28B-FA1C6E4D4D1A@ajf.me> <54DEE32B.6040706@gmail.com> <54DF5B79.6050009@gmail.com> Date: Sat, 14 Feb 2015 15:52:18 +0100 Message-ID: To: Stanislav Malyshev Cc: Andrea Faulds , PHP Internals Content-Type: multipart/alternative; boundary=047d7bb04ee4e6e707050f0d7f86 Subject: Re: [PHP-DEV] [RFC] Void Return Type From: nikita.ppv@gmail.com (Nikita Popov) --047d7bb04ee4e6e707050f0d7f86 Content-Type: text/plain; charset=UTF-8 On Sat, Feb 14, 2015 at 3:28 PM, Stanislav Malyshev wrote: > Hi! > > > What would be the point of *allowing* returning a value? It's clearly > > It's an error only because you declared it an error. > > > an error. We could let you return anything and then discard it, but > > now you won't spot the error in your code. > > Function return values which are going unused all the time. In PHP, > functions are very frequently called for side effects and not return > values. So returning value and discarding it is a common and perfectly > valid scenario. And it also has absolutely nothing to do with void > declaration - void declaration doesn't cause discarding the value and > you can discard the value with or without it. > > > It's not merely for the sake of it. It makes function signatures more > > descriptive, and lets you catch bugs in your code. > > Only bug it can catch is wrongly declaring the function to be void - > which is introduced by this RFC. For me, it is a clear case of > generating error for the sake of error. > > > We already use void in the manual: why not in PHP? > > Because the manual is the *documentation*, not code. It explains that > the function does not return anything useful. It's not the same as > creating an error when function returns something useful. > One of the primary purposes of having typehints *is* documentation. This applies both to our existing type annotations, to the newly introduced return declarations - and to the void return type. The advantage of having the type declaration be part of the language (rather than a docblock) is brevity on one hand and verification of its correctness on the other hand. It's easy to forget to update docblock type annotations, but you can't get away with specifying an incorrect language-supported annotations - if you use a wrong type annotation your code just won't work. The void return type is actually the one case where we can at compile-time fully verify that it is used correctly - which is great. Allowing to return a value from a void function doesn't make sense. If you want to return a value, don't declare it as void. If you declare it as void, don't return a value. It's really as simple as that. Nikita --047d7bb04ee4e6e707050f0d7f86--