Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119211 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11520 invoked from network); 28 Dec 2022 06:54:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Dec 2022 06:54:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B6C2E180339 for ; Tue, 27 Dec 2022 22:54:13 -0800 (PST) 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, T_SCC_BODY_TEXT_LINE 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-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 27 Dec 2022 22:54:10 -0800 (PST) Received: by mail-yb1-f171.google.com with SMTP id 83so15771479yba.11 for ; Tue, 27 Dec 2022 22:54:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=p+omEapcW+gzjsbgr6/BySAhkMkwt9rOcfkp6dyc1Ic=; b=PPgnSigEPLrUSA3ZgqPRpwfu4fMqV07D4IZ/3MYCmGIM86JKlQsOFwxAN3yB2ed1aW ogJ9KtOMIEqkGxNfigLbtIWjEexh3D+iQzd8DMM/xJKNzn91MsG5Y4K3cwxhGBjBMooi B6VEEZ72CNId30ZqiS32RpX4NKJN7Az9Q6Ccc+mMlKrj4p4tP6K3CVzcTHE8R1IX/ETy Y9NkQlnkPnzj7tHbg4A0lKNOP8JQjsYa7fJRnnrRUHWKZnCt+nadeXTGemR8fu07YU4K yebaIa5fj4KGLV7RoYz03i+zy+R7Bm02yx5zx49mINu1WhfXk/urgnIMdHxjlY0Djheu NIVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p+omEapcW+gzjsbgr6/BySAhkMkwt9rOcfkp6dyc1Ic=; b=0r2upfTkmv2T+dw9F4pPnrGR3wnBT/QgPMyLcnuemH+vhMio3oTrr4Twda8qVk2q3D K3MGJ06tcW7px7zYHxaag1HMH1Wequs32GvL5+EqFJ2PAtfNA2ANovRh4NIjcRqn0YQA 8a1ys0ITFzuz4tMXrBCOEOPqesl40swZpLjKISn03LZIAPwjVXslTEtzQtSJgcobBudh 9IA33SvEgXmhIlGCLqfkaVJOar0WQhN8ONLng3VgXyJT8sqW1xCwa5G+7GUTQ02u8f99 1/ua5LaxiUxIx3sVHyQ0Vzs/vLLft66v+pcM1ZGzuYs9zlJK/6ON8H0xZfAdjuqFwZY3 s2jw== X-Gm-Message-State: AFqh2kqyNfvKF5pJ8BwMOVyw3N6nn+AjpKR/XheQBfPV+6SC5WToBZ0/ CW1JDOk3hqtvQtSI39M1B8hXdeu4wQQ55SgOW8s= X-Google-Smtp-Source: AMrXdXvaejtMRSYzXYyLRgcrGeJ4pzqvzD434tsImipIv8hd5gVTQNgNm8GTcrmy1VqLPPI5fRK9lfC88GgtABknfbE= X-Received: by 2002:a25:2fcf:0:b0:75f:2c51:90e with SMTP id v198-20020a252fcf000000b0075f2c51090emr1489060ybv.67.1672210449529; Tue, 27 Dec 2022 22:54:09 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 28 Dec 2022 13:53:57 +0700 Message-ID: To: joke2k Cc: Claude Pache , PHP internals Content-Type: multipart/alternative; boundary="000000000000d5801005f0ddd550" Subject: Re: [PHP-DEV] Methods which auto-return the class instance From: pierre.php@gmail.com (Pierre Joye) --000000000000d5801005f0ddd550 Content-Type: text/plain; charset="UTF-8" On Fri, Dec 23, 2022, 7:46 PM joke2k wrote: > Thanks for the feedback! > > On Fri, 23 Dec 2022, 09:33 Claude Pache, wrote: > > > It is very common for fluent class methods to have a verbose `return > > $this;` ending in their body. > > But If you have declared `self` as return type into a non-static class > > method you have only two options to return: > > > > - the $this object > > - another instance of the same class or subclass > > > > ... in order to avoid a return type error. > > > > > > It is still two options, and it is not clear in general which one to > pick. > > You could also say that, if you have `object` as return type, there are > two > > options to avoid a return type error: either return the `$this` object, > or > > return another object. > > > > Yes but declaring `self` is more strict than `object`. > And talking about the word itself... Declaring to return (your-)`self` but > you could return someone-else of the same type as you. > But it is ok, it refers to the class name not the instance. just semantic. > I would rather endure it returns the used instance and not another one with a compatible interface. Not doing do is actually confusing to me, as per the meaning of self. . Or maybe, if the goal is to ease declaration of fluent interfaces (methods chaining), declaring a class fluent (annotation?) would achieve the same with ambiguous names? > --000000000000d5801005f0ddd550--