Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108070 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34041 invoked from network); 9 Jan 2020 21:47:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 21:47:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 159171804A8 for ; Thu, 9 Jan 2020 11:53:31 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3265 194.109.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from lb3-smtp-cloud8.xs4all.net (lb3-smtp-cloud8.xs4all.net [194.109.24.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 9 Jan 2020 11:53:29 -0800 (PST) Received: from [IPv6:2001:983:6fc5:1:5805:c45:243c:2a9] ([IPv6:2001:983:6fc5:1:5805:c45:243c:2a9]) by smtp-cloud8.xs4all.net with ESMTPA id pdryihVnxpLtbpdrziNlGk; Thu, 09 Jan 2020 20:53:28 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s1; t=1578599608; bh=UlnStUCKuP7b3jLvNVJu5ojhRMNp95dHLkRNPUmxAT8=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=JCeP5TogvPobiepn0E4ztts8/k8o/z3inJdvful7fHZtpRmdweOF+9MO83+Cp9DY4 enjAHCGA/7RKkMGNdVOsuqhCD3h3QzuX5eibAiFrYz5FGIVe8gqlNRAppokY8YYlQ0 UPlwTfCo0pDu1SaGQVhUXnbGxNfCAYptOOtUaPxYSsEjFE7JaZAiNjEVh5qYBp8eL0 v948Bo3nz041mLQsCBdL4SSrfJQhlhK6Hc+awHPGhdl7agLkf1ROolpe2eSd3wQg9k 6WnkjrNHCC7fBcB7XYjS/Chm5dKumVliMUzYA21KGxXu832j++EuyAptbniKSR9gch RC9pDDT0rYZkg== To: Andreas Hennings , Nikita Popov Cc: Rowan Tommins , php internals References: Message-ID: Date: Thu, 9 Jan 2020 20:53:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfCmEAFtMcGRk414W593/52a0Ytk8fzaENy3SyxjqrPIeRpV/poTqlqi/GxqRYJn5/7oBu/4bHFVWA2u6en8ROhK9xi1LkAsDGKoyMLYHkbhjfnlxj0fM Dkr5BsIjHNWNc46aX1qMFED/Se3CFMHfmSrjYzmhuE0ABjzlvZriSVc7F/0qlIxwBSuMsi1AZ8J6ajA0YmBFk0c42iW4tC8HrotUaUfkoIf5vZsenlHHgwaw ukQR04pKqD2nxry1u2ky9Iqnuj51iNUXtFEmKLfwEZDficpafq2O4jxactPD3fie1cp56ZI6iSqdW3UUwk/NeIe8mknvtkIpwvCbKF6PZQoZplJ691+cFZbx GYj21NE+ Subject: Re: [PHP-DEV] [RFC] Static return type From: d.takken@xs4all.nl (Dik Takken) On 09-01-2020 17:52, Andreas Hennings wrote: > On Thu, 9 Jan 2020 at 16:31, Nikita Popov wrote: > >> On Thu, Jan 9, 2020 at 4:06 PM Rowan Tommins >> wrote: >> >> An argument could be made that $this does also specify a certain contract >> to the caller: That the API may be used fluently or not without change in >> functionality. That is >> >> $foo->setBar(); >> $foo->setBaz(); >> >> must be strictly equivalent to >> >> $foo >> ->setBar() >> ->setBaz() >> ; >> >> The same is not the case for a plain "static" type. In fact, I think that >> for all other uses of "static" outside of fluent interfaces, not using the >> return value would be a programming error. >> >> But still, this kind of contract is not a type-system contract, and I'm not >> sure it's a good idea to mix other types of API contracts into the type >> system in this fashion. >> > > We currently don't have another "system" where this kind of info could be > specified. How about: public fluent function doWhatever(): static Perhaps this could be introduced at some point in the future to enforce returning $this. > And in this case, $this also implies static, so if we would use whichever > other system to specify $this, the type hint "static" would become > redundant. > > "@return $this" is common in phpdoc (*) since a while, and so far I have > not seen any problems with it. > > If we ask "where does this lead?", one natural next step might be to > specifically say that the return type is the same type, but NOT $this. > So, a promise that we really get a new object which we can modify without > changing the original object. > > I don't know how we would express this. Perhaps ": clone", but this would > be too specific imo, because whether it is a clone is an implementation > detail. Maybe ": new" ? Regards, Dik Takken