Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110673 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6286 invoked from network); 18 Jun 2020 21:43:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jun 2020 21:43:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A7E1D180504 for ; Thu, 18 Jun 2020 13:29:21 -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 13:29:21 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id z9so8852366ljh.13 for ; Thu, 18 Jun 2020 13:29:21 -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=wQjxsVgap5PXOrosNjOyqpRgEWpZ3cKeTdHUxrCLPFQ=; b=iEdulVZeOWruR4hdqPc35v4iikDbSPoKilwh+nBIfLmtKM9VOV0+r8c4GUUD5FjdFX N5Oi39P3e3YzLxlgAnpYRPCjMwyWM5SkfCJFRx2H0o6RCKMoc5A/opzwP2WrQNBeV3wd dLLm5zhxdRUfbsr1zWk4x2zsqj0fpNXi55XHe/tKEU+pk2pSQrVoGbxH8YGYuSPlzov6 Z5Gw0Lai02upyjFKTyl5Rh3aIBOglyowTn34axlQXZ/J+0l2QNI44EEiO0IN/Accukxf BAtOd0ceMiqNkciPRrQ4/cqOCWsvnKlyWmac/7SoQ71GTZITOHegONhouF5jBeszsLQe 3tgg== 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=wQjxsVgap5PXOrosNjOyqpRgEWpZ3cKeTdHUxrCLPFQ=; b=EtJp8iqWt1Pfa7AGqRnsI0xTnHdoQgzV1BlJeSb4T7dx669A3AGP92L1Ul959dlW3N n0s3Tchh7BO27nVX2/UXrUBfH38wtaBMB/ynBoDR8FrnOaT+i40YZQxwcBq4TBRtAAhc zWobkINbp3ISqT9AKOozebl6kRTVO4gcKM4TFfAxI+7XFhqNzPLgSxrzaC2OX6YUnTAi u512pws+gBTgqH1aNoFgibR4g4eAYOqnsN8gRlVHhui3Tc6s+pJemGLwVL+P7qCALNZw Ka6SGvO+Kl/vfPktbXa6IrQ8Frb0dfoLEttYUbc86JhntDTGjhrObwzIEWaSJMi1FS+4 LQjA== X-Gm-Message-State: AOAM532lQIl/kStSTNGpDOFKkdzYPRGnuw28shkH/U7LuP+e0xHBp7/w 875eHzvIbWtxgqB5Rs7lftgD3ZksGiPCMm20R2/EX78F X-Google-Smtp-Source: ABdhPJzmsbNw4QIV0GuaFaRjn+nRt3qpYtbJAhkJFjq//3ym7x4PAof9hKPy72BfJz956XTLEVcYDZMS71RHsT91JYc= X-Received: by 2002:a2e:98cb:: with SMTP id s11mr78904ljj.402.1592512158989; Thu, 18 Jun 2020 13:29:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 18 Jun 2020 23:29:05 +0300 Message-ID: To: Andreas Hennings Cc: Bob Weinand , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000897fe605a861a1f1" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Make constructors and destructors return void From: benas.molis.iml@gmail.com (Benas IML) --000000000000897fe605a861a1f1 Content-Type: text/plain; charset="UTF-8" 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. 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. 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. > Exactly my point. "Optional" means people will make arbitrary choices and argue about it, or look for a convention. Already addressed this. Best regards, Benas On Thu, Jun 18, 2020, 11:15 PM Andreas Hennings wrote: > > On Thu, 18 Jun 2020 at 18:33, Benas IML wrote: > >> Hey Andreas, >> >> That is incorrect. Adding an explicit `: void` does change behavior since >> only then the check (whether something is being returned) is enforced. This >> allows PHP 8 projects to take advantage of this enforcement while being >> respective to older codebases. >> >> Ok. I read more carefully now. > > 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? > > > >> And well, the explicit `: void` declaration also helps your code to be >> more consistent with other methods ;) >> > > Except consistency with existing constructors in other packages which > choose to not add ": void" to constructors. > > >> >> Without an explicit `: void` return type declaration, `void` rules are >> not enforced on constructors/destructors and will not be until PHP 9.0 >> (which will probably release in 5 years). >> >> Moreover, saying "it forces organisations, frameworks or the php-fig >> group to introduce yet another coding convention" is a complete >> exaggeration. In fact, even now there are no PSR conventions that specify >> how and when to write parameter/return/property type hints. >> > > 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. > > >> >> Also, it's important to understand that PHP libraries are really really >> slow at starting to **depend** on new PHP versions. It will probably take a >> few good years (if not more) until first few libraries start requiring PHP >> 8.0. As a matter of fact, even Symfony framework is still requiring PHP >> 7.2.5 and cannot take advantage of its newer features (e. g. typed >> properties). >> > > 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. > > > >> >> Last but not least, just to reiterate, the `: void` return type is >> optional and you don't need to specify it. >> > > Exactly my point. "Optional" means people will make arbitrary choices and > argue about it, or look for a convention. > > Greetings > Andreas > > > >> >> Best regards, >> Benas >> > --000000000000897fe605a861a1f1--