Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88820 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31923 invoked from network); 15 Oct 2015 16:09:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2015 16:09:41 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:35177] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/96-23021-4CFCF165 for ; Thu, 15 Oct 2015 12:09:41 -0400 Received: by lffy185 with SMTP id y185so34412790lff.2 for ; Thu, 15 Oct 2015 09:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=UUvlECoO+6IVaMypR7TdB4PWmcSUDcXmdPf7KyAdxv4=; b=jRw6mw2a5dS6jX6tupjiM7y66hykyT+e/gF3uybDn+u3tjWJ9F9OpsmAwR2XYXDqNE LnJi2AYiF19oA4lAey2b+xtQ5EANZHpl5Rh3O6UMr1q/MtuXHSPLHd4V/Nt3ZPnuLxZb HjyuspWuaNQsmCcuT5GtoNAyG1JqMjlnwvd466bLiLvMVKkBFvAiI4tqzvdGp7EmQTFG cXXWqM9YV+yFY/qvdNJ3wfPPyNnyFum3hrAw0QnLxkSpWxi9BQlVImbWGkV+poI1nTHy 8j81YtqYmYKcWKkDJXWY08+ttxbssGG0YO6HqqYHVWMa2CERKy8bltlyreuxvVBMZzbs 1/Jw== X-Received: by 10.180.96.166 with SMTP id dt6mr12206668wib.38.1444925377350; Thu, 15 Oct 2015 09:09:37 -0700 (PDT) Received: from [192.168.0.132] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id lb10sm17294637wjc.9.2015.10.15.09.09.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 09:09:36 -0700 (PDT) To: internals@lists.php.net References: <0A.C2.33697.6AECE165@pb1.pair.com> <561ED07E.4060809@gmail.com> <561F6718.7020900@gmail.com> <66.D4.23021.707CF165@pb1.pair.com> Message-ID: <561FCFAD.9010808@gmail.com> Date: Thu, 15 Oct 2015 17:09:17 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <66.D4.23021.707CF165@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: =?UTF-8?Q?Re:_[PHP-DEV]_[RFC]_Void_Return_Type_=28v0.2=2c_re=c3=b6p?= =?UTF-8?Q?ening=29?= From: rowan.collins@gmail.com (Rowan Collins) Andrea Faulds wrote on 15/10/2015 16:32: > Hi Rowan, > > Rowan Collins wrote: >> But why "invent" (as far as PHP is concerned) this new keyword of "void" >> to mean exactly the same thing "null" already means - absence of a >> definite value? > > They don't mean exactly the same thing. null is a value to represent a > lack of a value. But there's also the concept of *no value at all* (a > missing variable, say). The closest we have to that in PHP already > would actually be `unset`, but that's a strange choice given it's not > what we use in documentation (function prototypes, PHP manual, PHPDoc, > etc. use `void`), and it's tainted by the bizarro `(unset)` cast which > casts to null. Oh, lord, not this discussion again! PHP has no concept of a variable being in the "state" of unset; it has programmer hints to warn you if you read before writing, and a couple of odd constructs which let you access the current symbol table as a dictionary. The manual has some weird wording in places which implies that a variable takes on a type when first used, but in practice the rule is much simpler: any variable which hasn't had a value assigned yet is considered to have the value NULL, and normal cast rules apply from there. The same is true of missing array keys, object properties, unset() variables, unspecified return values, etc, etc, etc. They are all NULL. You could add a warning for "function foo() { return; } $a = foo();" to match "$x = []; $a = $x['foo'];", but $a would still unambiguously contain the value NULL in both cases, and outside of some odd applications like templating, it is *values* the program should be concerned with, not the *reason* for those values. Regards, -- Rowan Collins [IMSoP]