Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119781 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85299 invoked from network); 29 Mar 2023 19:54:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2023 19:54:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9BD241804A9 for ; Wed, 29 Mar 2023 12:54:09 -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=0.6 required=5.0 tests=BAYES_50,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, 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-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 ; Wed, 29 Mar 2023 12:54:09 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id u1so9588744wmn.5 for ; Wed, 29 Mar 2023 12:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680119647; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=iHYWuPwqP8Ilx8/5fgS8dm/1qL7OOGH87w9H0TlKdNM=; b=OUt4eDWxzay0nOovsCzrjFhfqbvVrSxMV4rZbnqpQrXVdi9Zj6QPbMeNlY0FPNaRbl AeG2rb5uab+A5XIewZD71NQLS7mo/YNN2rsP1JhPcHFA5+gHyrKIyW/BgIBry/LK7ikM aDJlG2PjaLSkyGujApMGaK3D0EdIxYFkvwlOViI3crQw2g8T6MpLQMmd8g/sqN4dyhLd qak8T+oK4xspZ8eJINpVn3bTmzlnHwPRnQTBMHxFRU6gh+GVMayU5C1aWfi/SbRBT9SV sX/p6h8cMlWrLMS9jDdCUm9JW7DmNAjaRzJrJFtNvUN77zr1tbqnL6qWWD//2FqqyKCD cvhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680119647; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iHYWuPwqP8Ilx8/5fgS8dm/1qL7OOGH87w9H0TlKdNM=; b=SUC/7TYpkDQPLsZYfW2suLyx+hswLN+vK+vtLOVQ9EWOKcTGbynmuVEr5mC6N9X3Ec 4SHTrOAMtJQGS8e+fo00zlvuK1DWxuytbYDDPLBk3WgfP8T7qfkH2h5ROjfkpFL6NFBa jlYLK9nsMpfuQqxD1ORAjXqBh9A8hODFVuglVNV89xRit6EBRf8km2LmCqJn8K4G30L3 88YwF+jlPhcIcfyDtoRL8GVbqj/RA5gLtuWubLfJASDBx2AaHLl8BfvpVcyVIYAWcBaj OcQsjdBuZkFac25uQ4LNCwocyVCb7RHOxIjjzJJP3hhTO8nO3IXdgEhHuB6irE+kcYS1 LxrQ== X-Gm-Message-State: AO0yUKXCoVd/Z4fI2YJyJWgBPBGn6188bPx8FRg8gp83PR6LTd/FW5N5 bM62KDpy8T+5aplfdcdNnO/f7eM9yd58APkZB5I7vZZVC0k= X-Google-Smtp-Source: AK7set8+bGtlrXkEwRcdRvznhQPqs0LLE+qMb0P7C7WrQuW+KcWmcDsj+fDJiUFQuzgPTGJyFEyEzTsr2lXLpFGWsUE= X-Received: by 2002:a7b:c414:0:b0:3ed:7664:6d79 with SMTP id k20-20020a7bc414000000b003ed76646d79mr4756667wmi.0.1680119647200; Wed, 29 Mar 2023 12:54:07 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 29 Mar 2023 21:53:56 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000c066ed05f80f56ab" Subject: [PHP-DEV] [RFC] Properties in interfaces From: fekzol.13ker@gmail.com (=?UTF-8?Q?Zolt=C3=A1n_Fekete?=) --000000000000c066ed05f80f56ab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =EF=BB=BFHi, [Proposal] Allow interfaces to define properties. The implementing class must have the same properties with the same name/type. As the goal of the interfaces is to define the public "surface" of the implementing class, I think that the public properties are also part of that. [Use case] - tl;dr; Right now I=E2=80=99m working on a product configurator. The input I get, I turn them into ValueObjects in the initial phase of the request. Then later based on some conditions, I turn them in a deterministic but very varying order into another ValueObject which has the same properties, but all of them are `readonly`. I tried to create somehow the same: https://3v4l.org/Vb7fE#v8.2.4 There are places where I have an array with a mix of them and I want to access the `$id` or `$axisOrientation`. I also have methods on them. I know an abstract class could do this for me but I feel that this would be the most accurate way to define what I want. [Example] ```php interface Vehicle { public int $serialNumber; public function drive(): void; } /* * This would lead to an error, something like: * Class Car contains 1 abstract property and must therefore be * declared abstract or implement the remaining property * (Vehicle::$serialNumber) */ class Car implements Vehicle { public function drive() : void { } } // This would lead to an error too, because the type is different. class Bike implements Vehicle { public string $serialNumber; public function drive() : void { } } // This would lead to an error too. The rule for readonly properties // would be the same as right now between normal classes. class Bike implements Vehicle { public readonly string $serialNumber; public function drive() : void { } } ``` [Implementation] Personally I don=E2=80=99t have experience in php internal development. I do have C++ / some C experience. I'm going through the PHP Internals book and every possible tutorial I find. I definitely would like to take part in it, and I'm planning to do more later. --=20 Bests Zolt=C3=A1n Fekete --000000000000c066ed05f80f56ab--