Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110829 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98749 invoked from network); 3 Jul 2020 10:19:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jul 2020 10:19:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D3B601804C3 for ; Fri, 3 Jul 2020 02:08:59 -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-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 ; Fri, 3 Jul 2020 02:08:59 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id b25so32513149ljp.6 for ; Fri, 03 Jul 2020 02:08:59 -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=AbMLfE845qN8EhvTsLggBOZjA8bB3HhUGZn+3Y4yrRk=; b=aEi3+C1yptuKmCFQoGocF8I2RDjBcGVfOoojmq3xLJlk64Ert46Yfq/vY6b+I9fX0b 6NR9Il3QxbK49brCQcUhb+iMrTctxJhaTWVjO3wIERa1KoCPHQ55l6jE23Ia4h6pA7iV YkZd/hQmOwJiIVKgP6XcpwZT3Nc6YDgELd1nKyGbwfIOcI+wFSGOgIcin9zw9peawNtQ 2SlI19J8S9kAzXCshLnuLQCz/bM1vI+3qPUAaONrG7jNEwkr7sjCY8q+BvC8HYkYKPKC exBJTYbLaYxjIdDEIZX7WYti1/sc2xMFH3QEkupO8Acm/xSHQo7QdS/TQebe861WCKme Yb9g== 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=AbMLfE845qN8EhvTsLggBOZjA8bB3HhUGZn+3Y4yrRk=; b=VhCkL1Nsbuvx+7gS2iXZwkZw3BWCs9662zeUBQISbaOFfLGR3iMnklE8D7letOTM6f PXf2J0XHH9m8ebh+5Gw/VfDRqHxkO4fg54UZSvHK7DfOUsHkboid+CXaDJ8acaDIDnXz VTtrPC7+ytcAMIK8CsWypFGsdOu/T3nVmyjUfVCnnL/XmeJ1TSi9nkZ6q+dpzBdXlNyN VNey6naKxzJ23R3enAalV38YI9BBXDF3WRfMq2XK11CfOYkaCz2edBImEd+27upDpb7R MNe23a5oqaSOyuWkAbcLf6vide44If/2ghZlD2iUg9NBI7CyULR/RNwx3C9rxUmB5YMS mHhw== X-Gm-Message-State: AOAM533NmzhKrk+/1bGtZV6U9DuAxitqvbp0R0kQclBekJFCutjD81QU xPUiKbSQebg8GsIgJ/nb5ir+pQ0Eai/qybM/q8M= X-Google-Smtp-Source: ABdhPJxMHmO8uQ9linGmOfnvTLblSZoIYF9PvkFVTebamuuGBFiA7EpXN3JrpmdHb4OYkC++JA5ahGDPkl7L0fwhE/c= X-Received: by 2002:a2e:9c59:: with SMTP id t25mr4977702ljj.402.1593767337051; Fri, 03 Jul 2020 02:08:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Jul 2020 12:08:44 +0300 Message-ID: To: Nicolas Grekas Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000fac74905a985df0f" Subject: Re: [PHP-DEV] [RFC] [VOTE] Make constructors and destructors return void From: benas.molis.iml@gmail.com (Benas IML) --000000000000fac74905a985df0f Content-Type: text/plain; charset="UTF-8" Hey Nicolas, Hey internals, >> >> I have opened the voting for the RFC, let's hope everything is going >> to be smooth :). If you have any other questions, let me know! >> >> RFC: https://wiki.php.net/rfc/make_ctor_ret_void >> > > Hi Benas, > > I voted "no" to the RFC because to me adding "void" to constructor and > destructor don't add any value: the semantics of these functions are > totally defined. Annotating the code with "void" is duplicate information. > I think that Larry's and Rowan's replies on the original discussion thread really well explained as to why it makes sense to allow an explicit `void` return type, so I'll just quote them instead ;) Larry: > I see this in the same category as __toString(). > Adding `: string` to that method provides exactly zero additional information. You know it's going to return a string. That's it's whole purpose. On the off chance someone is returning a non-string right now, they're very clearly Doing It Wrong(tm). However, the stringable RFC added the ability to put `: string` on the method in order to be clearer, more explicit, and to not annoy type fans who are like "Ah, I've typed every one of my methods... except this one, because I can't, raaaah!" > I see this as the same for constructors. Any constructor returning non-void right now is Doing It Wrong(tm), and you know that going in. But being able to make the obvious explicit still has its advantages, both for documentation and for consistency. Rowan: > As long as it's possible to return things from constructors, then it is > "obvious" that a given constructor is void only in the same way that it > is "obvious" that a method called "convertToArray" returns an array. I > would be surprised if any style guide would forbid writing "public > function convertToArray(): array", so would be equally surprised to see > one forbid writing "public function __construct(): void". In both cases, > the extra marker takes the reader from 99% certain to 100%. Another thing to consider is that the explicit `: void` declaration causes the check to be enforced in PHP 8.0. Meanwhile, the implicit check will only be done in PHP 8.1/9.0 (depending on the secondary vote). best this can do is open another code-style bikeshed war. About forbidding > the functions from returning anything, I don't understand why this would > improve the overall quality of anything. To me, this looks like gratuitous > strictness. > Quite honestly, every feature/change in PHP results in some kind of a code-style war. It is not possible to be "politically" neutral. Moreover, allowing `__clone` (as of "Ensure correct magic methods' signature" RFC) to have an explicit `void` return type but disallowing that for constructors/destructors doesn't make much sense. In fact, that is more likely going to create a code style war since not allowing ctors/dtors to have an explicit type would be inconsistent. `__construct` and `__clone` work in a similar fashion yet `__clone` can have an explicit `void` return type and `__construct` - does not. I also don't understand the secondary vote: enforcing "void rules" in 8.1 > is a not-allowed BC break. This can only target 9.0 to me, there can be no > discussion about it in a specific RFC. Or did I miss something? > Since some internals told me that PHP doesn't follow semver strictly, it would make sense to enforce the check in PHP 8.1 already. I raised that question in the original thread but didn't get any replies on that matter. Thus, I have put this as a secondary vote. This is just my opinion on the matter of course. Thanks for contributing to > PHP. > ...and a highly appreciated one, thanks! Nicolas > Best regards, Benas Seliuginas > --000000000000fac74905a985df0f--