Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115894 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51976 invoked from network); 29 Aug 2021 07:58:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Aug 2021 07:58:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A46091804AD for ; Sun, 29 Aug 2021 01:33:53 -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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, 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-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 ; Sun, 29 Aug 2021 01:33:53 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id s3so19899464ljp.11 for ; Sun, 29 Aug 2021 01:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=LwBw3ILiKS2pamQwW/2OlgwVlecV3mrJNRFI7GGWJQU=; b=k/QgNMpasFZkfQthkWoBGL0pTl6VROdjo1WmXYEPTldLLTW7Zth2EQXTPdCIhl3Wmb M3Vq123/QmIrOiuwUoqoDlbKPpL0VHsDLI9V8uRMhs1gbDi5pfUNOR1CMPbTIQ/a616j Gy06uOw+Iw2OEdwId/MdPltAGCGKKnRYnPjTvC7mIMMOzBv2iVzuLsaxvKcCoS+gihTn K3UisRo86UJAR9t9C5XSYNRjvZtAEdGVBytCCV1F9tdewb/1Qxa4KaTTrh/q12JljfXJ 5nJRcmQysjM/EPRRH8BWB/zjtrFBKmv0Cus0Tjbird/84lK0H6ABg6n3V6RmpOoARzsx 9cfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=LwBw3ILiKS2pamQwW/2OlgwVlecV3mrJNRFI7GGWJQU=; b=Ef8Fq7AhYsGNRh8kRNe+lqqdqRV2hYvcf9f25FzbJMAN6n278d0Alfu2UugkDb6TM/ W5HMJOo5dUsT1tOcz4gB3zIvrocWTht/+DxrPkA7QDGbNYC1xbwrGnsPR3ThOLcaToRN jZET0Z4UwyWzVvmeST6itwBwnJdilDa6vg6j/H9FrN+58Aos7g8zljJfnwJuE2XHusdv WNapFaiLGOLpzFj5piBoX+PbuLSrHTbLQ5RYwzEJxmf369fp4SeJwhm7WotQKRhZi71I F6gTQF6NWI+clB9OPl1BmhC33RHsyjHGcXGZPimdgXZLVkIZxbnrOesMDr6YDF1cgzOj uYsw== X-Gm-Message-State: AOAM531LvCPTuKlzDSH7qlGfL+gt3SFfSHGNVhYGtJCmiaMkxk8UJyK5 3nkZsaF+oOQyJLd5L0Ecm+7Y4/5BqSHwKJErI4w= X-Google-Smtp-Source: ABdhPJyG0kljFPvcFu/MtyZ2J158OCS992MLRyg4NzF4pkvJAbchdl1eHqDgW68LLdN/aBDkAW91brMhE7t0hKQ4jKY= X-Received: by 2002:a05:651c:11c7:: with SMTP id z7mr15460071ljo.288.1630226030361; Sun, 29 Aug 2021 01:33:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:6384:0:0:0:0:0 with HTTP; Sun, 29 Aug 2021 01:33:49 -0700 (PDT) In-Reply-To: References: <6074db02-5540-1831-e77d-0ed8f882a63e@gmail.com> Date: Sun, 29 Aug 2021 10:33:49 +0200 Message-ID: To: Mike Schinkel Cc: Rowan Tommins , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Make namespace part of runtime From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2021-08-29 5:12 GMT+02:00, Mike Schinkel : > > >> On Aug 28, 2021, at 5:12 PM, Olle H=C3=A4rstedt >> wrote: >> >> 2021-08-27 23:07 GMT+02:00, Rowan Tommins > >: >>> On 27/08/2021 20:47, Olle H=C3=A4rstedt wrote: >>>> As a followup for my previous post, I think this could be a good place >>>> to start to enable attribute writers to create encapsulation mechanics >>>> for composition, like namespace visibility, "internal" access or >>>> friend classes. >>> >>> >>> In my experience PHP projects tend to use namespace hierarchies which >>> are deep rather than broad, and I'm not sure how easily those >>> hierarchies could be re-purposed as scopes. >>> >>> Clicking through the Symfony source at random for an example, I found >>> "namespace >>> Symfony\Component\Messenger\Transport\Serialization\Normalizer", which >>> contains only one class. >>> >>> A trivial implementation of namespace visibility which just matched the >>> exact namespace string would be completely useless for that class (it >>> would be the same as "private"). A slightly less trivial >>> implementationmight allow access from "child namespaces", but that >>> wouldn't help in this case. >>> >>> However, it might be really useful to restrict usage of that class, or >>> some of its members, to classes in the "Symfony\Component\Messenger" >>> namespace; or maybe to those in the >>> "Symfony\Component\Messenger\Transport\Serialization" namespace. >>> >>> I can see two ways of enabling that: >>> >>> - Allowing visibility modifiers to specify exactly what level of prefix >>> they refer to. This is apparently how Scala approaches things, allowing >>> you to write the equivalent of "private[Symfony\Component\Messenger] >>> $foo; protected[Symfony\Component\Messenger\Transport\Serialization] >>> $bar;" >> >> Yes, I assume this is why Psalm introduced a new annotation >> @psalm-internal , which does take such a parameter. A PHP >> attribute can do this, _if_ it has access to runtime namespace. >> >>> - Introducing a separate concept of "package", either orthogonal to >>> namespaces or overlapping with them, e.g. "package >>> Symfony\Component\Messenger; namespace >>> Transport\Serialization\Normalizer;" would still give a class name >>> beginning >>> "Symfony\Component\Messenger\Transport\Serialization\Normalizer", but >>> would define "internal" to mean accessible within the >>> "Symfony\Component\Messenger" package. >> >> What's the estimated effort for adding package support to PHP? Did >> anyone outline a possible implementation? > > In case you have not seen these, which discuss possibilities but at a hig= her > level than actually how to implement: > > https://github.com/nikic/php-rfcs/blob/language-evolution/rfcs/0000-langu= age-evolution.md > > https://phpinternals.news/45 > > -Mike Oh cool, thanks! So there's more support in internals for doing package-visibility instead of namespace-visibility in the end? Or maybe the topic is not so hot? Olle