Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116894 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20773 invoked from network); 18 Jan 2022 19:44:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2022 19:44:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3E2FF180539 for ; Tue, 18 Jan 2022 12:55:42 -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=-0.2 required=5.0 tests=BAYES_20,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-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Tue, 18 Jan 2022 12:55:41 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id x7so362330lfu.8 for ; Tue, 18 Jan 2022 12:55:41 -0800 (PST) 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=k4av8ShV6jivSkcygy4/j4cV8W43Wu6JQlXUR4a6HxA=; b=SwpFvCwrtoAy98A1Y6gci+0JC8S5yb3dcCsQ8z19CH5REiSNBJ1QFKhRUqdhXyhW/H 5YSkny0oUgWCwWxxU+yQRXCuPclwtb9XeKN/oYuHVNgUdejuhJ57TCM3L19ZF43LM+9o Z+QWMT/3Rz0fhnAjs0gJpE0JioEpzOb0xhOQ5ESKIvfKjU6G68k9v8cfzpDAnh5Doct5 eC6SVunlFcpUFG6DH2SkqaVM/YAfE7ryJbp+7oHgfApRhCJQMKt8TngcFCPByEx7E5Z7 phpYNE6XNp/mIreTSaOnKq3smn9yLmgaLhrEW2w3E9Op7lkbGLk8bubDVJWJJiFYgxJA mHIg== 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=k4av8ShV6jivSkcygy4/j4cV8W43Wu6JQlXUR4a6HxA=; b=l4J9ayb0ljoiTW2cQ9KKkGwh9HpY5+gcVitnFc4QZOQ+P9uube9AfjCE85MvN/5gOZ J71uXcsnCp+X80EdYt/zZLCXrAtf/XRf2TJel8ygt7zim+RFmtjGgmm+DcLnR9OFQT5T Sgea9wg/muSzWHYSZxWkiSCvvhXsEXx9M0EEco1wvDVAqloXX/AFEFYNrD+vqxQ7n5QR KU3VaPqEPYOAaJwoSH2DnPLAZYlo9FuCTUg37uZES2zE3ChBDhGnAaFY2Ehz7DTMcWUP Z1X6TD0JgJVTURJoPRoboeJ2NH2jMAXTPsnV0/GEwHqR3zLEtGzUxgekNfIkJysocDfu Vl5w== X-Gm-Message-State: AOAM533ZPjNevWYB0J+ZnoVn+b/DKEf7XuRo3rGABqq7FeRa7lhkn/gN b1K1rhtAwEutxQCjhOlCkLqFo0WmMNEcRayd3G0= X-Google-Smtp-Source: ABdhPJytAm0IFe7AMKlDCX/foL+KhxgxgsBvAZGJTi5y3jAcWpTZdHQuOLD3jFBhJsmSW/5EzGrFRvkMYOhY6TW+owU= X-Received: by 2002:a05:651c:1509:: with SMTP id e9mr3908912ljf.25.1642539339695; Tue, 18 Jan 2022 12:55:39 -0800 (PST) MIME-Version: 1.0 References: <1641335738.195767637@f174.i.mail.ru> <5a4aebf8-e592-4517-8930-d18b112ef1fd@www.fastmail.com> <5a99809d-afda-546c-5a11-a4f0f821aa37@korulczyk.pl> <6E50C348-9452-40E1-ACE8-06DED11C9136@gmail.com> <9070564d-e138-81f6-c757-812d8962416e@korulczyk.pl> <23f78a61-a73e-eaa3-861f-75e9bca28485@korulczyk.pl> <262352f2-a3e6-272d-1118-5455497217a7@gmail.com> <6ABDE9F5-C69A-4FEE-9736-F2DED514184A@newclarity.net> <3543d7e3-9a26-25f8-8c48-d646431e84a2@gmail.com> In-Reply-To: <3543d7e3-9a26-25f8-8c48-d646431e84a2@gmail.com> Date: Tue, 18 Jan 2022 12:55:27 -0800 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000df478805d5e17dbc" Subject: Re: [PHP-DEV] RFC: Trait expects interface From: jordan.ledoux@gmail.com (Jordan LeDoux) --000000000000df478805d5e17dbc Content-Type: text/plain; charset="UTF-8" On Tue, Jan 18, 2022 at 11:13 AM Rowan Tommins wrote: > > The difference with the "trait requires interface" proposal is that I > don't understand what advantage it gives the author of the trait. What > decisions can you make as a library developer because you've said "users > of this trait must implement the matching interface" as opposed to "... > can implement the matching interface"? > > It's possible there is some advantage I'm missing, but so far nobody > seems to have presented it. > > Well, the trait doesn't necessarily have to fulfill the entire interface, first of all. As you mentioned, this can be worked around using abstracts in the trait. However, what if you're dealing with return values within the trait? Suppose I have something like this: trait ArithmeticTrait { public function add(float $val): NumberInterface { // Do math return $this; } public function addmul(float $val): NumberInterface { $added = $this->add($val); if ($added->isPositive()) { // Do stuff } return $this; } } In this situation, the return value of the trait requires that $this implements the NumberInterface, however there is no way for the trait itself to enforce this. Jordan --000000000000df478805d5e17dbc--