Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120809 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96121 invoked from network); 13 Jul 2023 18:02:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jul 2023 18:02:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F9A3180339 for ; Thu, 13 Jul 2023 11:02:33 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 13 Jul 2023 11:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1689271350; bh=dbUgym4cC65aZherxepcy3LGdlUmJB+SrzBZeeZldkw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=AaZJ8GhF6N4h/dmTUGKgKMBeUK7HATmVypfqkIKK3PsfYwnA2QovXAIz4f2Ufewxb 3HlIikZqUMHqgQ8XJfgtZSBi8h5mTN9WQbnXvjzmWe6rqPfXX0uUHMDyOIJCFA+zXY JJVFkuynpxfGKAGXVMvx1TEPwHgZ7dmcqb9kH3d/S923TlT53jfksYMRPDKgFFnHf6 kbh9nWPiGkDM6U4PBrtDeBGcSCH07KK0IuO21fe01FTNH0/mBC41Y/NgL12wXS0zE5 lYLy94S3gDccy3TdqtWmWGRqv8zEPgAIYlfTg1833T5i77OHyeClgCFGBFLRUV92z9 XuttpsTA6wy2A== Message-ID: <48d25edf-ce28-b912-c983-31ae5c64b6f4@bastelstu.be> Date: Thu, 13 Jul 2023 20:02:28 +0200 MIME-Version: 1.0 To: "G. P. B." Cc: internals References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [VOTE] Interface Default Methods From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 7/12/23 06:00, G. P. B. wrote: > I find the Rust Seek trait(/type class) a very concise example of the > usefulness, and where the implementation of a default method is far from > concrete. > Requiring an implementation to provide the implementation for seek(int > $position) > But being able to provide the trivial implementation of rewind() which is > seek(0); > (I'm not a Rust expert, but I've shipped production software with it. So the following might not be entirely accurate, in this case I'm happy to be corrected) I don't think it is useful to compare PHP or this proposed RFC to what Rust does. My understanding is that Rust methods are effectively just syntax sugar for a regular function call. Specifically they have an explicit parameter for the `$this` value (commonly called `self`). Furthermore "methods" in Rust are effectively namespaced using the struct or trait name they are defined in, thus implementing multiple traits with a large number of default-implemented methods with generic names will not cause conflicts: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5fe33b54187f110a8794c90e3a608466 In PHP all the methods would reside in a flat namespace. From my experience this can already be a problem when needing to implement more than one interface at the same time and this is not likely to improve if the number of methods in an interface would increase (e.g. the mentioned Iterator trait). The use-case of reducing the BC impact of extending an interface by providing a default method would also risk accidental collisions with methods that already happen to exist in a child class. Incidentally this effectively matches one of the examples given in my #[\Override] RFC (the 4th Laravel Eloquent example) - https://wiki.php.net/rfc/marking_overriden_methods#examples - though to be clear #[\Override] cannot (yet) protect against that, because "no implicit override" was left as future scope. See also: https://phpc.social/@heiglandreas/110649571908678102. This effectively makes the main selling point of the RFC moot. I'm aware this limitation is acknowledged in the "Backward Incompatible Changes" section. I do not think this makes it less of a problem, though. Best regards Tim Düsterhus