Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115888 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57726 invoked from network); 27 Aug 2021 23:27:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Aug 2021 23:27:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 55CC11804AD for ; Fri, 27 Aug 2021 17:02:23 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.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 ; Fri, 27 Aug 2021 17:02:22 -0700 (PDT) Received: by mail-qk1-f180.google.com with SMTP id t4so9009509qkb.9 for ; Fri, 27 Aug 2021 17:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OPKXOyv40DPt6uhsQRl4jFORU1+jZxcdWYrawtiYdIQ=; b=KcKjVkjEkTXNovgCQSLKYQgn/n3LQI1P1eL/HUA8xsoUgppMLVOQMYOXwjF1Rh0571 2hzZZ5QCqL+j83lXTqLuWiufkcK2b+diBF3Hu8Eap5cs6FRYuzuDtRYlXdPpVStViO7c z7RZS/HkX9pYyPpG5uKVlNxpyhDFqB9fuP/fNrzeUhWTYO355wCBdvTJaJbV5MYHn2dm sJ7c5f/0Ssl2yUQsvaJGNG8RMwezWYmEI2bLilCq3j5ZWqCZKN9uRKTGhjqAQQMgwUj0 ZK3NtDw6qAs1rAT6X/sVeTOk0wpVKyKA38+k8vD9ehCxtoVtqHf6WLhBAcLImSfBxPcd 4yzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OPKXOyv40DPt6uhsQRl4jFORU1+jZxcdWYrawtiYdIQ=; b=aAb1YwShBs6JhDJiVXSojpA05Ui1yWHOzKvBHE7vtQSh6pU15buygNTEjQ0LVn0tuV pN6IIbSU3xRVf+N92sp0EiWnUkCDt7lvoLDBtj1k0UspAjSGvdf9SRhRBzcWxsFL1bxY 52Z+8AdsS9Lld/SqMj0IoTAR6xVgDwLN5+eUoAS8d0tOPXrzxYSLxb1ueQIGC7Y4Gbb2 uZha8QcBCfE2BNNnYttWZ3miPNY+C3ps1NMt0SjEMDwjv4qK37fEIxgUK9Pgah7mJpjk I4Q9GQZcZqzA7vPpgvc/jgyGnJyzDVxhoYSGwKTZx3qlYkzwmfIGBm4FNt4ndRkfnunl d10g== X-Gm-Message-State: AOAM533NaM1WyGJwxgb0m/aRudLaZPVucz239uSYrMh0WZ+C7WHG4gpH hP/NlzRJkhjXzRUoZKqM+aL2Nw== X-Google-Smtp-Source: ABdhPJz+xs/+ws1xTVyYc8quQZ+9QfG6JmN5Hr8Hv/gxR6aZcK9p8R1MM1Vy0LHn9HhSru9M2SZdrQ== X-Received: by 2002:a37:a147:: with SMTP id k68mr11503141qke.416.1630108939738; Fri, 27 Aug 2021 17:02:19 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id l13sm4328977qtr.67.2021.08.27.17.02.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Aug 2021 17:02:19 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: <6074db02-5540-1831-e77d-0ed8f882a63e@gmail.com> Date: Fri, 27 Aug 2021 20:02:18 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <922FCDA0-F83C-4374-A1E8-76D59ADD6338@newclarity.net> References: <6074db02-5540-1831-e77d-0ed8f882a63e@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Make namespace part of runtime From: mike@newclarity.net (Mike Schinkel) > On Aug 27, 2021, at 5:07 PM, Rowan Tommins = wrote: >=20 > 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. >=20 >=20 > 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. >=20 > Clicking through the Symfony source at random for an example, I found = "namespace = Symfony\Component\Messenger\Transport\Serialization\Normalizer", which = contains only one class. I have noticed the same, including in some of my earlier PHP code soon = after namespaces became available. I often wonder if those implement deep namespaces did so because "it = seemed like a good idea at the time?" I have since worked hard to minimize depth of any PHP namespace = hierarchy I have worked with, and as a happy coincidence it reduces the = complexity of the code in the projects that use those libraries. #fwiw > 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. >=20 > 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. >=20 > I can see two ways of enabling that: >=20 > - 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;" +1=20 > - 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. +100 > 'm personally quite keen on the idea of packages, because they're how = a lot of PHP code is developed in practice - as modular libraries linked = by Composer - and I think we could optimise the language for that use = (e.g. applying more cross-file optimisations within a fully preloaded = package). Yes, agree. -Mike=