Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115877 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85324 invoked from network); 27 Aug 2021 05:21:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Aug 2021 05:21:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3758D1804CF for ; Thu, 26 Aug 2021 22:56:02 -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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 ; Thu, 26 Aug 2021 22:56:01 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id ia27so11396690ejc.10 for ; Thu, 26 Aug 2021 22:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GNYjdQ2erOHe2/IydZAxNr4fZg+VnXuiTX+YyMONPDM=; b=Z0ALZXbxFRAJgrNaSjDpZ3E5XxorUGq4qk97GUoallrMzxxxOBakSjAMOYQn91ZGOL gXMEIz64fWzIxTaBt2d8lKS6ij6bR+vv+2ESYrU95+uKtje2Rf5Ayee0liJh75sL+7er WUiHt3Dx+D5yA9I9/wVhjs35Bk1py55/1I00O5tWjsyYXokvvfJZ1/rD2flEW57Ou3Vo AM7Tmw58SLjvGilN1f2+YBLNr+a4D9kf1knjcVKQZ0omU35psyl2mTlzyqnC4ae/NJQu Xr8VW66cWND7bMFgDRS8c7Sb5ReR5TXl7De9zP6cog7leWN0OB9rqRAX6BJkFV19qHkF PKPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GNYjdQ2erOHe2/IydZAxNr4fZg+VnXuiTX+YyMONPDM=; b=k4uUyAESjywVG8u6FUcAjWboWmexTgGP92/KEQDUlgAqqQcIsq9eqqZaTKgpQHxQtw yi/j7RZoqcnMNEgLV9TToKDV6wCI929EwddRJ+bc/TNHDpzP7QiBnb4CbssxkaMxlyAL LY48k8hmC41yHW1gsApCnxFE2ma1VJpigmtXei/84Yx6ds1ZpkSWbGJFttTlZjB+A3EK qL1yyeCktt9nxGd75IqRJegcUUr5cl7D08/F6oX28yp7yA/idTsCdvu1+v7iRSt2VKAw vY+J/QXa3K7J4OyqAsJgKTvhIhErh2BsuyxlqB+QplG5bANXHi7+IO2AKOdsHOyPZm7f CFIw== X-Gm-Message-State: AOAM532dyldr+hPSn+i+AAxrOic4GQvAR5EBP0N4m3KRj1jUnYGsDjh+ T3ApR+NekWATH3IgMm3vavAagHPXQBlV6IYtzeEg+IlnusnsoA== X-Google-Smtp-Source: ABdhPJxuTGNVfkVQABuJExxlXJ+Eona6p78IgzncKakLGaUxn8+fMKzE2VnzjXFoUD/RvxgSVZxUaEhs3gDftM1pR/c= X-Received: by 2002:a17:906:fb19:: with SMTP id lz25mr8354162ejb.162.1630043760452; Thu, 26 Aug 2021 22:56:00 -0700 (PDT) MIME-Version: 1.0 References: <6ABFB65D-6F8E-4591-B36A-EA4B4CEC96A5@gmail.com> In-Reply-To: <6ABFB65D-6F8E-4591-B36A-EA4B4CEC96A5@gmail.com> Date: Fri, 27 Aug 2021 08:55:44 +0300 Message-ID: To: Rowan Tommins , =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000004f671405ca8423ac" Subject: Re: [PHP-DEV] Alternatives for encapsulation when using composition instead of inheritance From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000004f671405ca8423ac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 27, 2021 at 12:53 AM Rowan Tommins wrote: > On 26 August 2021 21:20:35 BST, "Olle H=C3=A4rstedt" > wrote: > >The Foo class has to decide who to give access to, otherwise it's the > >same as public access. > > > It does decide who has access: any class that declares it as "delegated". > In exactly the same way, "protected" gives access to any class that > declares it as a "parent", and namespace visibility would give access to > any class that declares itself in the same namespace. > > None of those actually limit access to a named list of classes, but all o= f > them document an intended use, and catch mistakes where that intent isn't > followed. > Well I wouldn't say they're quite the same. You can definitely limit the usages more with the "private" keyword. Or with declaring the class "final" for "protected" visibility, not allowing a "parent". I think something along these lines was asked. To have a way to decide the limitation by the original library, not by the one that decides to use it. Now... I also think that we might not necessarily need this. So far it looks like @internal works well enough. If a library is marking a class or method with @internal, it means it is not part of the public API and they might change it in the future. Static tool analysis like phpstan and psalm produce errors for using it. Also editors will warn you if you are using it. For all purposes you should treat it as private. If we really want the PHP runtime to produce a warning/error, even if this check makes sense mostly statically, we can think about a similar metadata with attributes with something like #[PackageInternal(namespacePrefix: 'Acme\Foo')] that can be applied to methods, classes and even properties and would trigger those warnings/errors when used from another namespace. This leaves the decision point on the library authors, not on the users of it. Regards, Alex > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000004f671405ca8423ac--