Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111896 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51135 invoked from network); 17 Sep 2020 23:04:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2020 23:04:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC96E180538 for ; Thu, 17 Sep 2020 15:13:36 -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-Virus: No X-Envelope-From: Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 15:13:36 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id z2so3262505qtv.12 for ; Thu, 17 Sep 2020 15:13:36 -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=8JAPJB6/vPoSzvo2DXBLhdGm87XI92S3R6ZuSaHYowE=; b=r3s++cKrvPpxhYSN4azlM6mEasMwLgYpcAZXXV+7RkYWvC9xe1c1qwtcJdfVbt6YBl CxYhWybZnYdRJrwydYSHC/KQ8p43sDbeFAt++am3mO80ScvJfQfZtcgiXJYCbrVQ9Xaj +E0GPbiT8VldoqS4LtEg0kq5a8ja8Yyjv3LLAgIrt7lFTexuBJRxb2oplJG00lcwx8mU LwlejdYmdD8o/P44LdAR8kLk6Z5Np4UkZmxKUt7Q/66ela3iUN4Rue2i64YTlhJ88k8S aC71j8pylSW/8dPgGmQSnSQpJWxh5YKpWy0fbcjSp7kzDZApxihIbNRhNotsGxHVC4/n 8wIQ== 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=8JAPJB6/vPoSzvo2DXBLhdGm87XI92S3R6ZuSaHYowE=; b=I4Bcezt2LSNfeUJfhJHnVgWKVgNFXvtJLl6YIkEtHVZLheKuAQtuIO6xlLGNeeIj31 SCb2BhJDUrGRLVfBtJDMKlyt1u68o1z54Anw33d8NddMseY0s0wj+idJ2EFZPOypSS2H 4nbv16pBrvl99NiDelOjlIGLKvCHbxIlqf6n0BdOZXWzOwLzIe/mECq5Wq2yB99FE8Ek 8dO+wUIDFVjfmLv7ovYOcmIQupvIX7R7N33ZrXsVZzuoi30dfeHleSmwZ9zw/A+//xsJ 4DOJNgR1iQ2vGtgZlRto5Dt8av4jkYf4uWKtJaoT0QXkFiZ4E6lFBU7C2L8xkHtwpDmg yCew== X-Gm-Message-State: AOAM5332Y8XAqRDS9yAO/2RpQNU8p2wUpqikHuBz/B35q4xDBCfvnY0G 9fjd/wj2s4PcFwUArF6VvAN6JzgS2fcnHnvW X-Google-Smtp-Source: ABdhPJztZk9JbIxcfjuaLmY9/i1E8EKNF5QpMvApIxXwrc6EPztePmlKgJJF984y0d30nIFYUWpXnw== X-Received: by 2002:ac8:3713:: with SMTP id o19mr29048404qtb.256.1600380814731; Thu, 17 Sep 2020 15:13:34 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:e900:edb3:6744:ed10? ([2601:c0:c680:5cc0:e900:edb3:6744:ed10]) by smtp.gmail.com with ESMTPSA id m24sm750758qtn.59.2020.09.17.15.13.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 15:13:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: Date: Thu, 17 Sep 2020 18:13:41 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <71C70A3F-4156-4CFE-B55B-CCE306FB9F0E@newclarity.net> References: To: =?utf-8?Q?Olle_H=C3=A4rstedt?= X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] Namespace-private class properties From: mike@newclarity.net (Mike Schinkel) > On Sep 17, 2020, at 8:28 AM, Olle H=C3=A4rstedt = wrote: >=20 > (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.) >=20 > (NB: This feature exists in Swift, described here: > https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) >=20 > 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. >=20 > Use-cases: >=20 > * Split data and behaviour into different files and classes > * Safely skip getters and setters without risk of properties being = abused > by client code +1 This might be able to address a use-case I have wanted for a while, = which is to have traits with properties (and methods) that are not = accessible with the class that uses the trait. =20 So if a trait is in a different namespace than the using class, the = using class would not be able to access these "internal" properties. =20 Or at least I think that could work? -Mike >=20 > Tiny example: >=20 > ``` > namespace App\User; > class User { > internal $username; > internal $password; > } >=20 > namespace App\User\Services; > class ProcessUser { > // Child namespace has access to internal properties, > // but App\ has not. > } > ``` >=20 > Possible? >=20 > Olle >=20