Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110677 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19311 invoked from network); 18 Jun 2020 22:43:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jun 2020 22:43:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 627F41804C8 for ; Thu, 18 Jun 2020 14:30:01 -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-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 ; Thu, 18 Jun 2020 14:30:00 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id n24so9033000lji.10 for ; Thu, 18 Jun 2020 14:30:00 -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=NcAgIOMb1+hBlFRgGSTW75YSCc1eRc/iSVTn97fX4pY=; b=rXkdj6bzPGXpehoMGEWpXycmLu+fCwv8gaAiJ2JqIEKI80WX32fsy2tuNavWycgHa8 DxcM2119EM6HlY8pRCb+639zf6duvY/9R8puZ9WjMu94ix4OAb2281oQHQnB/AhRb+fN SbcD4NjQYHEfwa8yRKO/BR4yMt0uN5w2HvxghUHwWNjKh8Ftoom/mo4vySCxmmXyhq4f gPIBHQTm5fISCyzNccW46LRn3yXXStKTvLRK5siT3B7DsV94QBmz+g0eztertHIKhVtN tt9m2IK/L9XVJG9ciL08miZonYuprA4y94YFW4aLpSheQBFwmc72/ubXFEXtWe5MPKH9 XJKg== 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=NcAgIOMb1+hBlFRgGSTW75YSCc1eRc/iSVTn97fX4pY=; b=g5zPy5br0aSKgRkvlVN1BXxBKmHYA2OgIeR1GRqAdVoSB+BljFbsJ1SiGnFXauRrWl xWIYpjvT3/AjIXLyw3zhJW2c7WeEIsKaLV5ElxHDEHrd69gV2rjdTtij50i51V2x05T0 EK161PXWKj3G6iUsQe9d8Nzi2LBNt4Zf7czAwKd+se9iYs8tZAPxCc1ac5zCZlbr83v8 A78j5kjqkz0rQyo8SAWjVrzBjRdi90quMsupgKZBkl20oXPBAPmrXHxNXlyM8xARc0si pNc1rWkmcDzi9cs30cILZydS/HTDi2UpYWXURlWTdNOvO0CLyEud71emlO7QAPCOIPzM ueyg== X-Gm-Message-State: AOAM533Ys8vl+0DS0mMRnyp0H+bBxpjZVXbvIvTm4oiP13PXZNp3pSpw zaSTe5FNqpnjlP9HQJjDSOVysjMHMq30mFZLJfU= X-Google-Smtp-Source: ABdhPJytwGq4wedDENTt3K7GG2SnSv3JEGqMxkNYYperJsB+s16SgF//+DosocgGAuFqjL5NTWPItBHFfuxJM+BDfjE= X-Received: by 2002:a2e:581a:: with SMTP id m26mr200500ljb.0.1592515799086; Thu, 18 Jun 2020 14:29:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 19 Jun 2020 00:29:43 +0300 Message-ID: To: Andreas Hennings Cc: Bob Weinand , PHP Internals List Content-Type: multipart/alternative; boundary="00000000000080fa4e05a8627a44" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Make constructors and destructors return void From: benas.molis.iml@gmail.com (Benas IML) --00000000000080fa4e05a8627a44 Content-Type: text/plain; charset="UTF-8" Hey Andreas, > Another example would be the "public" access specifier, which can be omitted and the method will still be public. > > There is a major difference though: > > If you look at a method without "public", or a parameter without "mixed", there is a chance that the developer actually should have put something else here, e.g. "private" or "string", and was simply too lazy, was not aware of that possibility, or wrote the code with a prior PHP version in mind. > Having the explicit keyword documents an intentional choice to make the method public, to make the parameter mixed, etc. `: void` on constructor/destructor also helps to explicitly show the developer's intention to not return a value. > There are conventions or popular preference, and there are people or projects which want to do things their own way. And here's another reason why letting `: void` is a good idea. PHP should not enforce conventions but at most recommend them and allow the community to have the freedom of choice. > On the other hand, for a constructor the ": void" is just stating the obvious. > Even if you see a constructor without ": void", you still know that this is not meant to return anything. > Either because it is generally agreed to be bad (PHP7) or because it is deprecated (PHP8) or because it is illegal (PHP9) And why that matters? Everyone knows that the `__toString` method returns a `string` and everyone knows that the `__clone` method returns a `void`. In both those cases, adding an explicit return type is allowed. > But here there are actual technical arguments why someone might prefer one or the other solution I never said that I was referring to people having technical arguments? Anyways, this is not relevant to the RFC > And of course there is the time before agreements are reached in specific conventions, where people produce code which could be one way or the other. > I don't see a contradiction here. Again, I'm not sure what you're referring to. Best regards, Benas On Thu, Jun 18, 2020, 11:49 PM Andreas Hennings wrote: > > > On Thu, 18 Jun 2020 at 22:29, Benas IML wrote: > >> Hey Andreas, >> >> It seems that you actually haven't read my reply carefully enough. >> >> > But this distinction would only apply in PHP 8. And the only difference >> here >> is whether returning a value is just deprecated or fully illegal. >> > In PHP 9, constructors with ": void" would be the same as without ": >> void". >> So long term it will become a "meaningless choice". >> > >> > Or what am I missing? >> >> The "allowance" of `void` return type will help: >> - to be more explicit. >> - to enforce `void` rules on constructors/destructors (in PHP 8). >> - to be more consistent with other methods (which is what people like the >> most >> about allowing `void` on ctor/dtor based on r/php). >> - to be more consistent with the documentation. >> >> > Except consistency with existing constructors in other packages which >> choose >> to not add ": void" to constructors. >> > >> > Either it is enforced in a "code convention", or it is up to every >> single >> developer and team, and we get silly arguments between developers in code >> review whether or not this should be added. Or we get git noise because >> one >> developer adds those declarations, and another removes them. >> >> I find these comments of yours to make completely no sense since most of >> the >> additions to PHP will create some sort of silly arguments between >> developers. >> >> A best example would be the `mixed` type. Based on what you have said, >> this >> pseudo type will create inconsistencies because some libraries will have >> parameters explicitly declared as `mixed` while others - won't. It will >> also >> create arguments between developers on whether they should use it or not. >> >> Moving on, let's take the `void` type (implemented in PHP 7.1) as another >> great >> example! Laravel and Symfony (both depend on PHP 7.2) don't use it while >> other >> libraries - do. So, as I understand based on your comments, this is >> creating >> inconsistencies and arguments between developers. Some say `void` should >> be >> added, some say not. Some libraries declare it, some don't. >> > > Another example would be the "public" access specifier, which can be > omitted and the method will still be public. > > There is a major difference though: > > If you look at a method without "public", or a parameter without "mixed", > there is a chance that the developer actually should have put something > else here, e.g. "private" or "string", and was simply too lazy, was not > aware of that possibility, or wrote the code with a prior PHP version in > mind. > Having the explicit keyword documents an intentional choice to make the > method public, to make the parameter mixed, etc. > > On the other hand, for a constructor the ": void" is just stating the > obvious. > Even if you see a constructor without ": void", you still know that this > is not meant to return anything. > Either because it is generally agreed to be bad (PHP7) or because it is > deprecated (PHP8) or because it is illegal (PHP9) > > > >> >> Moving on, attributes. If you go onto Reddit, you can see that the crowd >> is >> divided 50/50. Some believe that attributes are bad and say that they >> will use >> functions (for "adding" metadata) instead. Others prefer attributes and >> will >> use those. You can literally find people bashing each other for their >> preference. So that is creating heated arguments AND possibly future >> inconsistencies between different people/libraries. >> > > But here there are actual technical arguments why someone might prefer one > or the other solution. > > >> >> It's not possible to be "politically" neutral. Every single feature/code >> style >> is used by some group of people and isn't used by another. So next time >> please >> be more pragmatic. >> >> > So if you want to support PHP 7, you cannot add ": void". >> > If you only care about PHP 9, you don't need to add ": void" because it >> is >> pointless. >> > >> > Any convention would probably discourage it to be more universally >> usable. >> >> This is a completely contradicting statement. Just a few sentences ago >> you said >> that there will be silly arguments between people. But now as I >> understand, >> most conventions will probably discourage the explicit `: void` return >> type on >> constructors/destructors. Thus, since most people follow conventions, >> there >> will be little-to-no arguments. >> > > > And of course there is the time before agreements are reached in specific > conventions, where people produce code which could be one way or the other. > I don't see a contradiction here. > > Greetings > Andreas > >> --00000000000080fa4e05a8627a44--