Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115869 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54055 invoked from network); 26 Aug 2021 19:52:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2021 19:52:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 557B21804B3 for ; Thu, 26 Aug 2021 13:27:18 -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-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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:27:17 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id p38so9614279lfa.0 for ; Thu, 26 Aug 2021 13:27:17 -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 :content-transfer-encoding; bh=IoZyTBJRTL6VcXm0Y4SUOm3A8Cvu0i04iaycW5n9uLg=; b=kJQa0KtKpZHpPg+ub6nJaji3+xhYwt4QcBjAGBuJc1q5iSkJw2ofhrvtd89w+2D3EF VonbrahabNmveqVFqRSnu/k5U5x+j7ZmivXWfJqA9I/AyBIuR64W6XIuJgAwzKMtEaYd dAphkPwJYyqM9WjLwC8FNXdwLFMxJwjMC/ZHzmKBMzm0v4s7lNyKd9KEFwNRwMmOSVqy +/BllPul3QBl8bwHS+aCCqbwKWxX2b0ao4q1lvXnIdNPc19LupiitdI4jpEhINc9mKOH sbFVeRQt01yLF+7AXXXjwt3kqVq4SawThWTxYifN9/L/iD9vE7xtMnFffFQ737JGG+C6 LM0Q== 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:content-transfer-encoding; bh=IoZyTBJRTL6VcXm0Y4SUOm3A8Cvu0i04iaycW5n9uLg=; b=Y8eCAt3IaE1MJF661B1MYfjMdroNxTTy6FyMsrxfSjxZ+crHeSZK+i+gj/g2+n8SfO YXR6g1hZgr79KH+imri5UtE6kzEGZjtTkcCnw0rac3p4tPOBUxF5dU5waF+zdJEsWzTf fffJyDeUnndm+1a5A6m0LWamunNnvfNNriZFEr8f+f8bGMDMsZU9aeAUTO0ADxLTIrn+ Fw0K4AnqfmHz2A/n6R0ME0REwoj6uowjt/QPbhTESczv5PgEX/MrYy3Aw00dawy21R6W M8esv5nDBSrOghuugX6ZE3aysvL/z1H2qGAHUplElOmrh2aRSjAXr64V6g/KTOtRKqEA jOwg== X-Gm-Message-State: AOAM530zdA5Vk8+UpOMWgYDXerBDsH1+87SlbS8n3XD5cPpjwamkJTgG rsXwRFScmnpnbiWfBQmU50Wtg6KFxHRm1+pygJqBCcEMwtE= X-Google-Smtp-Source: ABdhPJwAxT+rqt8cZ8VsCVdpgxKEUa4c7QviSBNhHmGNKipMBso7YZAVtbFtgCh6a6dEU5StJ09I/lOw82vEbaw4ewY= X-Received: by 2002:a19:7b17:: with SMTP id w23mr3948688lfc.61.1630009636217; Thu, 26 Aug 2021 13:27:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:6384:0:0:0:0:0 with HTTP; Thu, 26 Aug 2021 13:27:15 -0700 (PDT) In-Reply-To: References: Date: Thu, 26 Aug 2021 22:27:15 +0200 Message-ID: To: 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 22:20 GMT+02:00, 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 Whops, Nikic already answered this in 2016: > The goto here will jump from code in namespace A to code in namespace B w= ithout "directly" crossing the boundary. For this reason just inserting opc= odes when a namespace starts or ends will quite cut it. https://github.com/php/php-src/pull/947#issuecomment-224934615 So, deprecate goto when...? Olle