Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116098 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73617 invoked from network); 19 Sep 2021 12:58:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2021 12:58:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1F6981804CF for ; Sun, 19 Sep 2021 06:39:18 -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=0.6 required=5.0 tests=BAYES_50,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-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 ; Sun, 19 Sep 2021 06:39:17 -0700 (PDT) Received: by mail-ed1-f49.google.com with SMTP id n10so49127884eda.10 for ; Sun, 19 Sep 2021 06:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+E6eYeStEHKiak0nmSSL44vvdm5xt7hN0Pl7AlrZSbQ=; b=bIVr4HjC/urvQePrBdQQcz5bBCEmXItNoPr21BbKCDGAp4VKY01Pw6sxy4bz/Y29IO I1+P6y+WB84ftXkuj8e6K0rHw6qxNb4VfRDgQ96peK0cWDDKYMxz4Q11h7rX3/kH1y0o N+VDa78PfE8nHj50ZgMC9mtX1Y9Ke6MffcD6Ofda6DegMFNYtovTXfoQHCjIbrhzeNIf LeXiYq1Sdsd7btfdcjiHbluTgJtNQL7Hb1Pu0jJ6oej0I8Fp0tceIBPzn0+FUEVhbNhG E7S1/7WRwS56M2MX4XjeMmourMRIkf5ibGdYlcHESlvZiNzxVpwSkA+r2Z//XxmHpWGo njRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+E6eYeStEHKiak0nmSSL44vvdm5xt7hN0Pl7AlrZSbQ=; b=njfGU84EHXvmbidxRwWhZwFbGHDTMIQ82G8YwFC7K/wA7pTSJl0IdIgKNtbIRClIuw RSoxb8rQ1plxGukshafc9D6LtvhwxB3iOST3An5Q020VNEsnQiyypvEijynPrPDoQQTY 5ZyjZfl9KgrW2kNmvuH7izYPWjkftVFgIpkow4WjP5IH3Bbp4Zkc7A5DlG78KYBQmjdV QRRA+hDy9B8E9VK5N8zqICPnsJ0T3VYQVQSoV0LR5qOx6lPf2avIISQ2r7uXjaJInk7+ qA8dXZ14Nq3AesOfHXl1h1W2F2S6ZcGqwskXyej6PszoVKmhD46RaUWJ7RNO0uMhL4sh Mlag== X-Gm-Message-State: AOAM532clkGNlOrD8LaWd0d5dTnbLHz7pi4d0nXrbvd4LSa7IooBrJG9 ouyztWMFEVSxQrbPMzSfZwqXr5da251mfbDsB1kkmLsimxM= X-Google-Smtp-Source: ABdhPJz0LhvHvfBqOMiBovWaBRXStRcgW2drW44j4CMfG/iEgilphCBFdxEUcCPv35k0SjIZCuL7lcXdqsw7LNBmnfU= X-Received: by 2002:a17:906:95d7:: with SMTP id n23mr22266962ejy.479.1632058753176; Sun, 19 Sep 2021 06:39:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 19 Sep 2021 15:39:01 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003c5a6c05cc594a7d" Subject: Re: [PHP-DEV] [RFC] $this return type From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000003c5a6c05cc594a7d Content-Type: text/plain; charset="UTF-8" Hi Nikita Hi internals, > > I'd like to pick up a loose thread from the future scope of the > https://wiki.php.net/rfc/static_return_type RFC, the $this return type for > fluent APIs: > > https://wiki.php.net/rfc/this_return_type > > I have some reservations about this (which basically come down to $this not > being a proper "type", so should it be in the type system?) but I can see > the practical usefulness, so I think it's worth discussing this. > Thank you so much for the RFC. I'm really looking forward to being able to use $this as a return type. > On a dataset of 2k composer packages, @return $this occurs 29k times, while @return static is used 38k times This is really good to know. It makes it pretty clear to me that being able to declare $this as a return value would be valuable to many projects! As far as my experience is concerned, I tried switching from the `@return $this` annotation to `function (): static`, which is the closest approximation currently supported by the engine, when I realized that this would loosen the semantics of the corresponding interfaces and kinda force ppl to deal with the return value while this doesn't make sense in fluent-style APIs. I therefore kept the annotation in place and I'm now looking forward to being able to write this declaration using native syntax - with the added benefit of having it enforced by the engine. About the syntax, I think the one proposed in the RFC is crystal clear. I've been used to seeing the "$" symbol when reading `@return $this`, and this just makes sense, past the first surprise. I also think that using "this" (without the dollar) could too easily be confused with something that means our "static" (esp. considering that TypeScript uses "this" in place of our "static".) I'm reading in responses that $this is not a type, but I fail to understand how that makes it an argument against the RFC. Neither false is a type, and null is both a type and a value. Yet we have them because they provide clear added value. Having $this could benefit 29k times the top 2k packages. It doesn't look like a niche use case! As you might have understood, I support the RFC and would vote for it as is personally! Nicolas --0000000000003c5a6c05cc594a7d--