Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110595 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47129 invoked from network); 16 Jun 2020 15:34:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jun 2020 15:34:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1AE4180549 for ; Tue, 16 Jun 2020 07:19:38 -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,HTML_MESSAGE, 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-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 ; Tue, 16 Jun 2020 07:19:38 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id i3so19223486ljg.3 for ; Tue, 16 Jun 2020 07:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=liQEpBJr5yy5kZrXZaMtBPndDC+WljrixVOnjdP5+7s=; b=Hls3QlRFr+xgX9yfOomZ7nCaKK9HwlJB3S1m2F5IBPzyUiA7v4arCiqw9RuylnHZ03 ZvuVmckGyV0iG3QuoguP3uyX2EcOJuggT9bne5txjgmn0dcDKkC4/HosbXWw6OpeoAku 4nhlSjsjpaYyT4r6+ikXfmg8wYNnznsdTTSgbl9Qtb20jALMEDQhVBtFrlO5xBQB0Hbs r+IUkjhJfiqwVJ3y2EtF/e+Fv3CxtPJBC7mJvpV/9PTOHY+ELpGSzfJ1V1oMUi7RreKy XlSic6w1vrMoRZ4TeFkl2cx/yij4N84WIZ+JTB6Sh6YNnimSDoBhSmbN7/G4zZuffIjv AorA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=liQEpBJr5yy5kZrXZaMtBPndDC+WljrixVOnjdP5+7s=; b=DiGqmvzTuPWZRGe5w+QZCpwNqFg07AG4Tv8r4y7b6y48lSyS3GHfzZqsv2ACawUPPw Z/Tiu30ODPI8tb8t7EVq/G64JVVIBOJeyCDtofyRYTJPVn9I9kfvgwdmIPyQbl9Ph2+h y8yLOjiz38j8AMTiGX2M0cHP8Dbta0z95mlfnwuQ4Ue9+WQN0WyBWqcC4yhmiYqBTKPQ DqXTztkICvHM6fXCHxm3H4I/Wvep08a7EujOXhM9cOaeSC6eCMrMG2DWiCAejimn//bH 4c8tvWbOXx6w3RlCMSV23NjXKs3k2BWCn4OXxLnTVQuKiHwg0PUUDAxLTg9OV7ofcDZt RDBA== X-Gm-Message-State: AOAM532Gh36ZW0QP62etEK8hO8cSXMrD58l6/FHqhpMo8in5DnsQA1Zn aTAxnjka1PQ/xD1Dz1gHv7/s6zPq4NOh+PfqxsU= X-Google-Smtp-Source: ABdhPJy1eAtkzEx+00KNq6GmzDJ25f171vsVpyUq8BJquNsQdJkUzYmVBJmakbs2F/AUm2bxATszE/xsv4VkX//6AOc= X-Received: by 2002:a2e:92d5:: with SMTP id k21mr1525136ljh.445.1592317173852; Tue, 16 Jun 2020 07:19:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 16 Jun 2020 17:19:21 +0300 Message-ID: To: Dan Ackroyd Cc: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= , "G. P. B." , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000846d6505a8343bd0" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Allow void return type for constructors/destructors From: benas.molis.iml@gmail.com (Benas IML) --000000000000846d6505a8343bd0 Content-Type: text/plain; charset="UTF-8" Hey Dan, Thanks for your reply. > No return type is _treated as_ 'mixed|void' in some circumstances Could you elaborate? No return type DOES mean `mixed|void`, could you give any pointers as to where that is different? > I'm actually not sure exactly what you're trying to say there I meant something like this: ``` wrote: > G.P.B. wrote: > > Seems like a no brainer and a good addition. :) > > For situations where stuff is simple, 'no brainers' are okay. > For situations where everything is horribly convoluted, 'no brainers' > are often bad. > > Benas IML wrote: > > even though no return type means mixed|void > > Not quite. > > No return type is _treated as_ 'mixed|void' in some circumstances > particularly signature checks during inheritance. That's not quite the > same as 'meaning' the same. > > > What I meant, was that since no return type means `mixed|void`, > > you can't do the following: > > I'm actually not sure exactly what you're trying to say there, but I > think pasting the text I reference whenever trying to think about LSP > might be useful... > > "PHP allows contravariance (aka type widening) for parameter types to > obey the LSP principle. A subclass may use a 'wider' aka less specific > type in place of the inherited type for a parameter." > > "PHP allows covariance (aka type narrowing) for return types to obey > the LSP principle. A subclass may use a 'narrower' aka more specific > type in place of the inherited type for a function return." > > > I am proposing to allow void return type for constructors/destructors. > > Constructors in PHP have multiple issues that are 'surprising'. I'm > not sure that fixing only a small part of how they are surprising, > improves PHP drastically. > > Also...I really wish we already had null as a usable type, as most of > the uses of void are slightly inaccurate. > > The meaning of void and null are: > > void - this function doesn't return a value > null - this function returns a value that has no information in it. > > Presumably you want to be able to specify void as the return type to > make it be easier to detect errors in code like the example you > provided. > > It seems that making a rule for whichever static analyzer you're > using, that errors on any assigning of a value from a __construct > call, would achieve that, without touching a part of PHP that is full > of edge cases. > > To be clear, I'm not sure if I am in favour or against the RFC. The > real problem is that constructors just don't fit into how we think > about normal functions is PHP, because of the magic that goes on > around them and so both void and null as return types would be a > little bit incorrect. > > cheers > Dan > Ack > > > > Some example functions using those two return types. > > function this_is_void_return(): void { > exit(0); > } > > function this_is_also_void_return(): void { > throw new Exception("no usuable return value"); > } > > function this_is_also_also_void_return(): void { > while (1) { > echo "Hello world\n"; > } > } > > function this_is_null_return(): null { > // deliberately empty. > } > > // This code is fine. > var_dump(this_is_null_return()); > > // This code is never going to execute the var_dump, which > // might indicate an error. > var_dump(this_is_void_return()); > var_dump(this_is_also_void_return()); > var_dump(this_is_also_also_void_return()); > --000000000000846d6505a8343bd0--