Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88826 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42966 invoked from network); 15 Oct 2015 16:41:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2015 16:41:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=pedronaroga@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pedronaroga@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.175 as permitted sender) X-PHP-List-Original-Sender: pedronaroga@gmail.com X-Host-Fingerprint: 209.85.160.175 mail-yk0-f175.google.com Received: from [209.85.160.175] ([209.85.160.175:33914] helo=mail-yk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/F8-23021-127DF165 for ; Thu, 15 Oct 2015 12:41:06 -0400 Received: by ykfy204 with SMTP id y204so60260371ykf.1 for ; Thu, 15 Oct 2015 09:41:02 -0700 (PDT) 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=GmS8QKI4P6K3hu4qZfvwJEaLvRVYF0W8gHZDq6owJaU=; b=R7+8MaATUzg4eQhhbNpZhvbzMeGurQGQS4hMvxbGgKUGpf7rDVdY/cXWMH+Pw5TYm9 YS/dkawceTEWs3VmnbDCeMrds5g4zoj19pRr/qIptk2/jvpZ6XAfGA9a+iLxrrs9GNcs 4YLnq41HOP0F+3VEk9ZzFD2pZ9HKWNbgdBjvwHiQMdc0mMyqeXWmzCbIH5rzQOkKiHwP HXoqwHFh3uNh//145gAg1rmzMbom4sq5tbQF801mW4ZiwRvKzffvvMBthuUiqDD0VowI BInt8cEL5YIAFKxKAdyHWDqT0hQjd8p5R5lXFSxkWXmXpcay0dchWIrU5uyvnOtuE1x+ 8z+g== MIME-Version: 1.0 X-Received: by 10.13.235.16 with SMTP id u16mr7274365ywe.26.1444927262773; Thu, 15 Oct 2015 09:41:02 -0700 (PDT) Received: by 10.37.108.195 with HTTP; Thu, 15 Oct 2015 09:41:02 -0700 (PDT) In-Reply-To: <90.58.23021.E85DF165@pb1.pair.com> References: <0A.C2.33697.6AECE165@pb1.pair.com> <561F7D17.5050306@gmail.com> <561FCD9F.10104@gmail.com> <90.58.23021.E85DF165@pb1.pair.com> Date: Thu, 15 Oct 2015 13:41:02 -0300 Message-ID: To: Andrea Faulds Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=94eb2c086dea3978d90522275860 Subject: =?UTF-8?B?UmU6IFtQSFAtREVWXSBbUkZDXSBWb2lkIFJldHVybiBUeXBlICh2MC4yLCByZcO2cGVuaQ==?= =?UTF-8?B?bmcp?= From: pedronaroga@gmail.com (Pedro Cordeiro) --94eb2c086dea3978d90522275860 Content-Type: text/plain; charset=UTF-8 > > this would make the "void" keyword feel more meaningful. I, too, had issues trying to understand what "void" was bringing to the table. IMHO, it should warn people thinking some specific function/method returns a value when it doesn't, not protect against some dev forgetting the function he's writing should not return something. IMHO, it's far more important to warn "Hey, this function returns NOTHING, don't try to use its value because it doesn't exist!" then it is to warn "Hey, this function can't return anything, stop trying to return things!". Throwing an E_NOTICE when accessing a void return value would make perfect sense, as the compiler would strict check that the function author defined a no-return and indeed returned nothing and would also warn whoever was calling the function that it doesn't return anything. > We could do this, but I do wonder if it might cause a lot of E_NOTICEs to pop up for existing code, assuming we applied this to built-in PHP functions. My proposal is to only throw an E_NOTICE when accessing a return value from a function that is explicitly marked with "void". A function with no return ("return ;") but with no ": void" on the signature would not necessarily throw an E_NOTICE. function myFunc() { return ; } $a = myFunc(); //NULL should be assigned to $a silently, like it is today. function myOtherFunc() : void { return ; } $b = myOtherFunc(); //NULL should be assigned to $b, but an E_NOTICE is thrown. 2015-10-15 13:34 GMT-03:00 Andrea Faulds : > Hi Pedro, > > Pedro Cordeiro wrote: > >> I've been thinking about what PHP should do when accessing the return >> value >> of a `void` function, and so far, I think the consistent thing should be >> to >> get NULL, while throwing an E_NOTICE. >> > > We could do this, but I do wonder if it might cause a lot of E_NOTICEs to > pop up for existing code, assuming we applied this to built-in PHP > functions. > > I'm not sure. > > Thanks. > -- > Andrea Faulds > http://ajf.me/ > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --94eb2c086dea3978d90522275860--