Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115892 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21731 invoked from network); 28 Aug 2021 20:37:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Aug 2021 20:37:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 407161804AD for ; Sat, 28 Aug 2021 14:12:25 -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, 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-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 ; Sat, 28 Aug 2021 14:12:24 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id p38so22442642lfa.0 for ; Sat, 28 Aug 2021 14:12:24 -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=H0gC4PybqhiSkhrtSUSiUFF6koTwzpfO3zOTbug1f9s=; b=hqyd1RbEVgTyQzm0jozaJPRoUitdSWh0qYk+l6h5vUMFVw4Y/l/3qd0zJchUjMiFAt A3rWT5EZwEzGrZkUA1LrXmIoRS8HOzfJ+F7flE9YT6y4zPObW3mA6TwHqTvRY7PR9nlM /UeAe/uJCTF7pDYMwRyBGDH0ebXLtxWarcbnLW1+mZB56/PwOL1Cl5am+6QOuZ3ftR1X irBxliX3S+vQFa2Le6VMckLTJENub1KO7u2ghGruaBJnRO+wmrQmpGFHSzHYFfd2xRUZ NVmSC+ZkGB++sFrvZKhWo6tsrYr/PjxUW6e/xi6k4OSKq0hZChs01tyV9AEHuOBbC8P/ 51LA== 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=H0gC4PybqhiSkhrtSUSiUFF6koTwzpfO3zOTbug1f9s=; b=P18wnxfVFHEpBP1G+AokmeXmz+WY0x60ojN0zy/+8YvdNB+Gze8tYPXaewvtyk21X3 lB1lZrGyf+DhY7rAnzqdZS6W360jc2T+jw+/HPOQq8MS+Gz5MQ9ODl8pTGbHQv3pBfaO 7WNYHdCrWRjT1JT90ErLOBFBNkIgHCG9KPiyjdDmfg4kiXefn9OSLkRkflstYjpkc2qU RAKEh6QTY0aK0By/Eo8ZV6IQ6AQAflK4Y0dgXYCB7dQ8cuu9oWiAnUw2N9SWT4xmElX2 1uTugWQOA9omaXY2GaDN1/rLg3YEWYCM94yVpifJvmKuksDHvERR83x/7n3mjs+5q4wx gqeQ== X-Gm-Message-State: AOAM530mtJHv+clPgVY2mHmNBu0Hj+rde1YTa8v01lP2KYYmpV08LKlZ 1jQn6q89boQmb85g3mMcXT12ari6vIfJZ43EJc0= X-Google-Smtp-Source: ABdhPJykhY70kG3dxCkHqu1GVTuPTvnPsxkvDiZRzSEHTub1DnA4pawSRfEqFpL7W5r+o2pa09qAcAKRQIXjf3ROCq0= X-Received: by 2002:a05:6512:3b7:: with SMTP id v23mr11435958lfp.41.1630185143176; Sat, 28 Aug 2021 14:12:23 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:6384:0:0:0:0:0 with HTTP; Sat, 28 Aug 2021 14:12:22 -0700 (PDT) In-Reply-To: <6074db02-5540-1831-e77d-0ed8f882a63e@gmail.com> References: <6074db02-5540-1831-e77d-0ed8f882a63e@gmail.com> Date: Sat, 28 Aug 2021 23:12:22 +0200 Message-ID: To: Rowan Tommins Cc: 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-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? Olle