Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119590 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58025 invoked from network); 21 Feb 2023 16:15:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Feb 2023 16:15:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D42101804A9 for ; Tue, 21 Feb 2023 08:15: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_H3,RCVD_IN_MSPIKE_WL,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-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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, 21 Feb 2023 08:15:27 -0800 (PST) Received: by mail-pf1-f170.google.com with SMTP id g12so2820623pfi.0 for ; Tue, 21 Feb 2023 08:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1676996126; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mhchSepMwk6w3qTdrq+NBw1THiqPAeQmBftG9pGSurg=; b=PX4rBEnlnqQGJV2OYsbNzmJ/gxcYAxSdcadKbvjJccDrKZQdR4405GjfO3Dc+j1UAS 3Zi85Zr0gCJbnwlT8uSKexW1nu/8clf8f0CwHrSPXR/dum7lLEu1rPwa9WioHGrhaNvY 97aAQrmtjT7drfdvpBqwVMmudUQ1fTZNYdys8wbX396ufWYvkWS8DfYYGsBZONtqDGrS uOiTFoJCp3WkQ9lK6X1QQpRsbzDfJHgXsLujG9fcd224N2WLlCvVgFJVHjDvjeFnGNg+ fiV7Q+BQLNfdEEoSFFo4BoiPbcyD0qi7eeHF2QUPAOXBZHspopvLXSy525rqiy0Ldc6m I/nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676996126; 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=mhchSepMwk6w3qTdrq+NBw1THiqPAeQmBftG9pGSurg=; b=v2rFeM+78PTwfIOoFm9lAYbK/X6EId/3XI5g5pFes2EVn8AelVaA1GlxoWp6y+GJcT s8mMlT/Wyt0g+OP3qxx5a5ku0tavxdnPvQPOVpCVM8FiEuT80NP3rfvWKteswqPgUO36 PGYTv4aooSEJA9PE8ehqu9Y0RlWpv1p1zUncKLPBKG03743rRbaPzd78C7XyDTD0teya RaF/X9p0BFd8M3fJLQ6crF/+z0N/J47JFFcoqNEmvU6AHUIeNYDnEwrDus5aq7o9+/zd ty1T+F37jO41UgKtoSfTb4uePyXcTw9teH5SpbaJAS7FLsjafg7ycQRHwFBrEpXs14ky nWZg== X-Gm-Message-State: AO0yUKU3MiNpeHiF5mW7+9Smx7D8a4Aw51DA59ylP9sKOpldUdYfS2WD n7VGJmHT3SR5JlhfexvBBfxx2ecaGplHXMkHjhY= X-Google-Smtp-Source: AK7set+0YvAi3DGz3iMx8Ak6u9jRgtSoF5f6PuwESA1+apJZhjA/9qayVwrfGkhMoGbIU7GeIqxRdgC0JA2YKmYaTpo= X-Received: by 2002:a62:ceca:0:b0:592:503a:8f06 with SMTP id y193-20020a62ceca000000b00592503a8f06mr626864pfg.52.1676996126187; Tue, 21 Feb 2023 08:15:26 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 21 Feb 2023 18:15:09 +0200 Message-ID: To: someniatko Cc: php internals Content-Type: multipart/alternative; boundary="0000000000006426ec05f53816b2" Subject: Re: [PHP-DEV] Class Re-implementation Mechanism From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000006426ec05f53816b2 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 21, 2023 at 3:30 PM someniatko wrote: > > This sounds interesting but it breaks some expectations. > > > > Interesting because you can have any class act as an interface for other > classes with the interface being built up of any public properties or > method that exists on that class. > > In my original suggestion, it's not like any class, but only those you > specifically mark as `class interface`, not just `class`. Closer to > the end of my idea I also suggest that maybe it's worth it to allow > implementing, like interfaces, ANY classes, not only those > specifically marked with the new syntax, but this indeed brings up > some issues. > > > The expectation it breaks is that if you have a final class, whenever > you use it, you expect some specific implementation exists on it. > > And this would break the expectation and in real life someone might pass > a totally different implementation. > > Will not break generic LSP but still will break some expectations. > > That's why a new syntax is brought up. This expectation might indeed > break if we allow to reimplement any existing final class, instead of > requiring a manual opt-in. > > Understood, thanks for explaining. So it's mostly a syntactic sugar that allows defining an interface for the current class that is already implemented by the current class. The interface name is the same as the class name and based on the context, you either use one or the other. There are some places where this could get in conflict like (new ReflectionClass(A::class))->isInterface(). But also internally things might be difficult to sort out to know what to use one or the other. To have a perfect syntax-sugar, why not also allow the interface name to be specified? Something like: final class interface(ServiceInterface) Service { public function method1() {} protected function method2() {} } that would generate: interface ServiceInterface { public function method1(); } final class Service implements ServiceInterface { public function method1() {} protected function method2() {} } As explained previously (and now I got that), autoloading will not work in this case. But some classmaps can be configured for composer or you could just force class loading with class_exists() in limited places where this is needed (in tests). Alex --0000000000006426ec05f53816b2--