Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115868 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52632 invoked from network); 26 Aug 2021 19:46:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2021 19:46:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A92161804BE for ; Thu, 26 Aug 2021 13:20:41 -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-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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, 26 Aug 2021 13:20:41 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id y6so7376872lje.2 for ; Thu, 26 Aug 2021 13:20:40 -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=nFVYtXcQH3u9tHq30wNkJQ1cyJ471nklq3VwBMKuLpE=; b=piobvur8k/tCBh22LWIExZPEoLx8UamZSVwil9A4pYKNLz43W7+R+akGrjZvIKUH2G Q66wdfJTvPPt3irhnFqiJrTReYDowT8dodEt4+Y+SPDcUDdynStU+mRypaAW8xPltPcA xydV2EtEl8PDRyT6ojIZM5bazeyTtLdJYX4yP/rQDK++4+Dc4bdXi5bRFToEC9KnbA9G PTNBsRkLa4LuxApzRuXtkAL4+L9AnlZq4Y1raM8jjHVds0V1NAt5uWiUlw+lkRXI8XW0 H376BocF0TbZR3STfeFniRIsFOxESsMdGckHul9Yez8XYxLOB38B2XHnoUFWuLVByyAW HcFg== 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=nFVYtXcQH3u9tHq30wNkJQ1cyJ471nklq3VwBMKuLpE=; b=V1ITI5QYfNBILaogbyax2R6SLGJX1Xhhdhj1FEg2ZHOC64QcEsxl+XtRsi8lxugaLs dz7AUrbEWcV/2/Z+r5fratw/pR1xmzp0zjmcxUFVM/B2USjLpB9Eac9srGBCvYcCunBX ZvCWtJ+X8YQf4J7mmoEpoaARoumT8nkdA+d+L0X4dSKDs1yhTLdD8FOVqeHay1UVZGk5 EiUOwtqJmuC6vKM6NopP3ALq5aEXMIKGXuXqEnywcucSy9p+WKJDpVcB/Z9U5p9Ectcp qxSy0MKcw2MwXq4G/kVEm2aoa/N2WtRZt1RQz4hoRuRKlR9ThYSUk5jwRy9ARWHTSiin kW0A== X-Gm-Message-State: AOAM5303BtyE0vP72tDqk8oFvAjOQ2Igpuviq+NB3lqJo7LLwwdRjhBC SX87i41snnAPcg0i5/eWkndqmcd/+/Tn+kiGhrA= X-Google-Smtp-Source: ABdhPJyysmeaouASYGXVj54A7zchZLjiDG2sbTNxmjQpYZN8Y+xXL682hF8GTgDzMw5Y8A4Gd5Yj/qg6JZn6EZxnRp0= X-Received: by 2002:a2e:95c1:: with SMTP id y1mr4561219ljh.71.1630009237082; Thu, 26 Aug 2021 13:20:37 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:6384:0:0:0:0:0 with HTTP; Thu, 26 Aug 2021 13:20:35 -0700 (PDT) In-Reply-To: References: Date: Thu, 26 Aug 2021 22:20:35 +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] Alternatives for encapsulation when using composition instead of inheritance From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2021-08-26 20:30 GMT+02:00, Rowan Tommins : > On 26/08/2021 14:47, Olle H=C3=A4rstedt wrote: >> Don't know if this already exists, but maybe we could consider >> brainstorming or gather alternatives for different types of >> encapsulation when using composition? > > > Although not quite equivalent to your suggestions, these threads on > making delegation to an encapsulated object might be interesting to you: > > * https://externals.io/message/103353 > * https://github.com/php/php-src/pull/5168 Right, there are indeed a bunch of attempts and suggestions, some downvoted, others abandoned. I'm thinking adding namespaces to runtime might be a logical first step. That would allow attributes to add logic like internal properties for a certain namespace. Makes me wonder why that never happened for this PR: https://github.com/php/php-src/pull/947 Asking anyone on the list, would it be possible to make an opcode out of "namespace Foo\Bar" and letting it set a flag in the runtime system when run? Then make the flag accessible with a constant like __NAMESPACE_RUNTIME__ or whatever. Ooooh, there's an interesting case with "goto" and namespace visibility here: https://github.com/php/php-src/pull/947#issuecomment-419821198 That would mean every zval has to carry in which namespace it was defined inside. I wonder how that would affect the memory footprint of PHP. > If we had something like that, then perhaps there could be a > "delegatable" visibility, which was the equivalent for "protected", but > when delegating rather than inheriting, e.g. > > class Foo { > private int $a =3D 1; > delegatable int $b =3D 2; > } > > class Bar { > private delegate Foo $foo; > public function __construct(Foo $foo) { > $this->foo =3D $foo; > echo $this->a; // Error: can't access private property of a > different class > echo $this->b; // allowed: access is to a "delegatable" > property, in a "delegated" context > } > } The Foo class has to decide who to give access to, otherwise it's the same as public access. Olle