Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111876 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79461 invoked from network); 17 Sep 2020 13:19:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2020 13:19:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 182851804C3 for ; Thu, 17 Sep 2020 05:28:09 -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=-0.7 required=5.0 tests=BAYES_05,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-Virus: No X-Envelope-From: Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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, 17 Sep 2020 05:28:08 -0700 (PDT) Received: by mail-ed1-f50.google.com with SMTP id k14so2364296edo.1 for ; Thu, 17 Sep 2020 05:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=wubjYwmu3KX/2Vaa3w0DM4bneR4GXpt59hCZ7op8EO4=; b=LrtmbMUqLt+ZGP49umGkMudpqNQQIaWmCEs1QSdieVmsjaUEUJHlp+r0aQ8zkbUJ71 L6rup7mUxEQWlrmof9abY/nXEYhsv0BIGlXZCZp6L9/nQbS39QRWwSh4RMuur34s38wE aGMkdSB0Ipbsa79iOfeQJKAiiwXU28pgbKjzcjmpeHND55jHj1r2PETMfNASLwf1PF2V uJcWgQ7diTzDFkr0dDovqejyWo0Jm8Bh0PyDGJivxQvMxfHN/31LEXGDpH5iou4yUKtO Bxo3wkajm6JMiif+Nqc5UfJq5E5fB7rmb98TGmkNBcn4Pl4rt6LIU8OmyndfWSVvyRx1 LrZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=wubjYwmu3KX/2Vaa3w0DM4bneR4GXpt59hCZ7op8EO4=; b=h0yqMAm2edOpAZLGoBGf28BqtZa+lDOiYT4ERn0fY4bc8NisRjb5ymRRKEdzLv8BI0 390WlDVCDzSPsk3bEHtt2AeHg//T5EyjkYEUx7r/GGEk/4FgcuSU0DTyvufRrFvAoH9/ yhoX95PTrarK1hlTPB2I+RufHCpSklMogeCL/H7/rNxhD4tbh1QMtMbU1pyPJ23Hu9I0 lYSSP/fOBhM5Aj/JD5q5mSP1Pqm9N4pr+Wke+RBgFgeM6I2nAB04XrDbq6OzdVqeSZ70 7k5tQN6apcQeT8Jigvp+6L+jNGYGLMIrYJouVpL6Z/pBqJjPus8regjLVvfUc8AftAMg arrw== X-Gm-Message-State: AOAM5324PA9cX+xeXK0UtB7w0fsu5+QcCHQ4CpxTAw6jY0OJqJJzvZAe MLv171QHEtveJwqT2lKfir6DS8YtOMFDGHYGPVG2ymGP X-Google-Smtp-Source: ABdhPJzFwZmALM1kZ0SFySH62FDd2hDvTgKjGL1SG8MUYenanHP9/r+xki6CDewQaZgn9N+ZFaVrEg61KeAxurIFQ0g= X-Received: by 2002:a05:6402:3075:: with SMTP id bs21mr33129676edb.236.1600345687203; Thu, 17 Sep 2020 05:28:07 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a54:3ac6:0:0:0:0:0 with HTTP; Thu, 17 Sep 2020 05:28:06 -0700 (PDT) Date: Thu, 17 Sep 2020 12:28:06 +0000 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Namespace-private class properties From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) (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, we 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 abused 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? Olle