Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111901 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14610 invoked from network); 18 Sep 2020 10:15:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Sep 2020 10:15:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 757871804AA for ; Fri, 18 Sep 2020 02:24: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-Virus: No X-Envelope-From: Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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, 18 Sep 2020 02:24:01 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id nw23so7161353ejb.4 for ; Fri, 18 Sep 2020 02:24: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; bh=x1XP6jP9OTMwJSB1XXk6PFz2ze7OSsUuaQfZ4yf2/ok=; b=RHkMJCUVQLlU3QdJ0Dn3brZhgmPAUZd7LggLBSsNqQGFxFjBXGnxjx8q+G2kjDrAEb DjQxLLT6XkT6OKmL5f8x5XLtH/GYsTfC0sgsBaSWyMjc1zj78hmKuE43hZqRxi+VthgI WwFxr1dhkKOsE0CTzAxjRucbsOesTbMWS7A2eAKxcGj8Fb+y0qz2M+0u2is6J0rQjk9y TWJPAdaFe3sMm2x0+0hHnfMar1HTFRtyAM88Udm7bWAuI/evM3VxZszHWc0hGCCntzBt LCkjE4w7yUXwAEjW0pki/QtSmtwj9BPKgkPkzy8MG83Q2IbHyDhrrIQaY3g3BAfDtp+S Mckg== 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; bh=x1XP6jP9OTMwJSB1XXk6PFz2ze7OSsUuaQfZ4yf2/ok=; b=hxR4prBjXTZQ1TGET6AyYJ47LLOlVXCOXwYh/4t7pqJxN/Iw44hUfQwZVXgUUnsA0f UtoMhqHGnrAqsHms1MZ+PcdBpjwHFLf451Zg84/+VRkpXFdIL/rB9l19v6VG2XwAigQG 7THq6yn3mra89zZm8a6kdyozRNSUf+ywKFk0gKHTLQnERZdFof2yl1K/ZYLhy+LXW4ZH 6ps6gdJUeoMubZtY030MGUQRyPMNH3iZ1jKoNh3aj9+iPb6W6XXER6xa+Av1rkazT2Of h1KnMiuz6FEcvWRoCg8KH2LSC9AKGghEHsiQioAKLJRDJZFI4EeP8uGtLKszsbO0NDa6 j1qA== X-Gm-Message-State: AOAM533sTnL/1UbReSnpB6Hv+SyZ32d/PTUNLlVgEyw1HhHLJbRYAZ2w lt/LVJOttQsrYQnBdsNZE2AcIqrB0iL+6ZasDZBJ+uEH X-Google-Smtp-Source: ABdhPJzPB3Ir0aH1IOyK+rtbbauiEw4JVYK/cYa3NpDEmUMO1Zl/bl/aKmp3MzMD8CGNcx3lW/REh9ZXd7aX3h5bnpo= X-Received: by 2002:a17:906:3955:: with SMTP id g21mr35239822eje.69.1600421039498; Fri, 18 Sep 2020 02:23:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 18 Sep 2020 11:23:47 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000008ce8fe05af930f9a" Subject: Fwd: [PHP-DEV] Namespace-private class properties From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) --0000000000008ce8fe05af930f9a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ---------- Forwarded message --------- From: Olle H=C3=A4rstedt Date: Fri, 18 Sep 2020, 11:23 Subject: Re: [PHP-DEV] Namespace-private class properties To: Micha=C5=82 Marcin Brzuchalski On Fri, 18 Sep 2020, 06:15 Micha=C5=82 Marcin Brzuchalski, < michal.brzuchalski@gmail.com> wrote: > Hi Olle, > > czw., 17 wrz 2020, 14:28 u=C5=BCytkownik Olle H=C3=A4rstedt > napisa=C5=82: > >> (NB: This idea is NOT about namespace visibility for classes, interfaces >> or >> traits (already discussed here: >> https://wiki.php.net/rfc/namespace-visibility). >> It's about adding a *new* visibility qualifier, call it "internal", to >> make properties >> private inside a namespace. The purpose is to make composition less >> fragile by not >> exposing more than necessary.) >> >> (NB: This feature exists in Swift, described here: >> https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) >> >> We have public, protected and private. Since PHP has no module system, w= e >> have no qualifier to mark a class property as "private for this module". >> One solution to this could be to add a new qualifier "internal", to make >> properties public within the current namespace. >> >> Use-cases: >> >> * Split data and behaviour into different files and classes >> * Safely skip getters and setters without risk of properties being abuse= d >> by client code >> >> Tiny example: >> >> ``` >> namespace App\User; >> class User { >> internal $username; >> internal $password; >> } >> >> namespace App\User\Services; >> class ProcessUser { >> // Child namespace has access to internal properties, >> // but App\ has not. >> } >> ``` >> >> Possible? >> > > I say it's not possible. There is no control over use when you pass > reference. It is easy to load class in "child" namespace which extracts > references and pass them wherever. > > Keep in mind that namespace on PHP is just a class/funtion/const name > prefix and nothing more nothing less. While it may work in languages with > support of modules in PHP there is no such thing. > > Cheers, > Micha=C5=82 Marcin Brzuchalski > Hm, does that mean that PHP doesn't know which namespace it's in in any given moment? Is there no "context" tracking in the compiler? > --0000000000008ce8fe05af930f9a--