Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116824 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97557 invoked from network); 5 Jan 2022 22:44:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2022 22:44:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B0371804A8 for ; Wed, 5 Jan 2022 15:52:27 -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 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-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 ; Wed, 5 Jan 2022 15:52:27 -0800 (PST) Received: by mail-ed1-f48.google.com with SMTP id o6so2831642edc.4 for ; Wed, 05 Jan 2022 15:52:27 -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=ZSdhbrFJoIVaM5Ul/afelOz9Aal9TUUmfGnDaTWJn0Y=; b=cYQk2KsKc1qX1N37wYIJAvKfhybfYYp7P3rGcq1F5z232m83yqI3z0ht7ADNp297Zv wFJnidFcM68hZHyp4bTKZ4QyOk7ouDkpr+U+iSzctzle0pe+57W3e4/ieLMzDDH+7/T+ dw7o+TfNviPJOmocMXtbO6OhX0OBnU1YWHAEaIzjeYwDuBT2aK19tWeOZfh+nB6LAlL1 4AdnoZqpav5nsyms6lPcscuLQphg/gMSuzTgGT7F+lDCVqB8AyAA6zcyM+KfoQC9/Wmo 9GQSsWsdlJTk1mhyt+9+uZYTc/GtXdKUlpB2plcuM6hzlFMxHxc0zLX1VqQ0D21Pl+mT mWpw== 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=ZSdhbrFJoIVaM5Ul/afelOz9Aal9TUUmfGnDaTWJn0Y=; b=OJOOZp8AfGYTcfnvu7Z3SkEbg2k4pzZ8GmK4ol16Js+rODuUREqiv9uD3qnwOYRyI0 EvvXEXvmgns+NeuzXdZVQaZit/HLkdlEBowu2KvMCfaW/D5FqF3RM+eNhtI0gO6Ypxze UpuyYvY/lLxnsoSK5eVYp7THbCO9JrzbwHfYdX5YN5CI+FihnqG/2/WRIjRgfpfvB2zM j7/ki1QWvTxiwAVLncn9Jo94+B7ck7JlGu38eHjMlrI8vjNCkXHKqvxuRnEKWyyuKSkz +JlLNNf85eGL0d0RP4H0p215DxTAad46Plbcuov8KNYx+2PT8FR8NuhjCgxvWrUc3H7V VIQQ== X-Gm-Message-State: AOAM532h0ejSmt/umhl+U+46xDBvQ7FIOT2Q8T1uDbAVqMj4y85j8KKd nETiymNZJfulVNWH2J9Hwh3/fm6H4JGa9tf/a65EMoFrS+w= X-Google-Smtp-Source: ABdhPJw92Hk67LZVKTVdqQXA00I7FCsgfwtWHFrJuv7bGi16PN7kqePvehWQ2YvYPAJl4KTmoQEJjqnf3aI6GK2dbCg= X-Received: by 2002:a17:907:7817:: with SMTP id la23mr43638663ejc.731.1641426745885; Wed, 05 Jan 2022 15:52:25 -0800 (PST) MIME-Version: 1.0 References: <1641335738.195767637@f174.i.mail.ru> <5a4aebf8-e592-4517-8930-d18b112ef1fd@www.fastmail.com> In-Reply-To: <5a4aebf8-e592-4517-8930-d18b112ef1fd@www.fastmail.com> Date: Wed, 5 Jan 2022 23:52:15 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000001d081e05d4de729c" Subject: Re: [PHP-DEV] RFC: Trait expects interface From: davidgebler@gmail.com (David Gebler) --0000000000001d081e05d4de729c Content-Type: text/plain; charset="UTF-8" On Wed, Jan 5, 2022 at 11:05 PM Larry Garfield wrote: > On Wed, Jan 5, 2022, at 2:35 PM, Chase Peeler wrote: > > For point 2, that's mainly useful as a way to signal to other developers > "hey, this trait has all but one method of the LoggerInterface, that's how > you'd use it", and to signal static analyzers and refactoring tools the > same thing so that they can be auto-updated if you tweak the interface. I > can see a use for point 2, and it would make my life a bit easier, but it's > overall not high priority. > > I think existing constructs provide 99% of this benefit anyway. interface I { public function hello(); } abstract class A implements I { abstract public function hello(); } trait T { public function hello() { echo 'hello'; } } class C extends A { use T; } // or alternatively class D implements I { use T; } // or abstract class E implements I { use T; } class F extends E { ... } $c = new C; $c->hello(); // $c is instanceof I $d = new D; $d->hello(); // $d is instanceof I $f = new F; $f->hello(); // $f is instanceof I It's not quite as neat as directly having a way of annotating T to say it implements I, but it does the job insofar as your IDE and tools should be able to immediately pick up a change in interface I is not fulfilled by anything relying on trait T to be of type I, either directly or by inheritance. The remaining 1% of benefit could probably be achieved just by naming convention: interface LoggerInterface { ... } trait LoggerInterface_FileLogger { ... } But I still think both goals would be better achieved with something like: interface LoggerInterface { default public function error(string $message) { $this->logger->log('error', $message); } } in the manner of Java...no idea how easy or not it would be for someone a little more experienced than me working on PHP core to do this though. - David > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000001d081e05d4de729c--