Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104649 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14111 invoked from network); 11 Mar 2019 15:25:00 -0000 Received: from unknown (HELO mail-it1-f175.google.com) (209.85.166.175) by pb1.pair.com with SMTP; 11 Mar 2019 15:25:00 -0000 Received: by mail-it1-f175.google.com with SMTP id l15so6889653iti.4 for ; Mon, 11 Mar 2019 05:14:38 -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=EoMpGIRM5BqkDoV54y/qD+ykVFe9Xm+JCuywJ1CGTfI=; b=pDwdNqJ21+KTEsXgle6BA1HUkv9jAqyBh98OThZ1zpIfzm2N7chFcM0OZW/D+W7OQk Cg1VgpHHMcDonK0F/YzzaiBwMbCRPPJkZS2r8XjjRdVzb1AQFhzFn5H+GMQudo2OxAGy x7ejDNtHiV75jLeP/c5G4iBjkdYCMZy4/oky3bECKAAmhFUPVuvveBNO8GIWr1qhopIW oSmZRfIZdsGMKLqWpxRB6Nhr8TDmbhu31nXFgeBgIIG+EXuISnQj2do97IAtnkrM3h1f kIT1f6uo8g+X9Xurm8NZpzUK8f5spe+/O/Oruxy9S5ADeqcct+ZYxPZmLWKME/VWyaZL Sjnw== 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=EoMpGIRM5BqkDoV54y/qD+ykVFe9Xm+JCuywJ1CGTfI=; b=DR4yqUZA6S+yofiCmtacb8RK66KvVcoC/3DbESnVvFNvklmEqteCFdw3V+JqN7ONk3 6js5FW86C8RJ9aD2A9ncuv4rOt7jAZClZ++NssqN1dpnAP4NJILciKLyRU4TJB8T3/PF HWfFaNUhnR5HfEl67EqPytFntwV7yxHP6NCjQKPRFAeY8PbJ4GG66W40fA1SH7srS7hf nAaE0ZFoO2WOEqSF9i0AtALqmj/1otjIFb/lnezhWu2+DXCIJvIjugW1lJBY4ZaF+c1c WtJr+NdgJTPNP7gFXTQYcVSOnVWuux3B0FzilClBR7KNOxbtdxh+MrZxqm5Uq25/yWPF jrzg== X-Gm-Message-State: APjAAAXEk6WHeVvwIBt+ZCCkwvDSvF5agFsRefRMj3hl58HyII+ctP65 +CFIk92DZ0cfGSEuUy5TOlgpfbMbDjlE7qE49n/b2r4p X-Google-Smtp-Source: APXvYqwlj5HAhlCSL6euQbwgES/BBdbq8XiUC8pemNEAIj2u6xyMWS/0QjpsAHQZ5GwyuC5Ds/07kt8tfF19sJqbNyQ= X-Received: by 2002:a24:10c9:: with SMTP id 192mr16130908ity.34.1552306474544; Mon, 11 Mar 2019 05:14:34 -0700 (PDT) MIME-Version: 1.0 References: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> In-Reply-To: Date: Mon, 11 Mar 2019 12:14:23 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000ff74f20583d08369" Subject: Re: [PHP-DEV] RFC: Locked Classes From: rowan.collins@gmail.com (Rowan Collins) --000000000000ff74f20583d08369 Content-Type: text/plain; charset="UTF-8" Hi Nikita, On Mon, 11 Mar 2019 at 11:27, Nikita Popov wrote: > The solution I would prefer is the ability to declare that within a > project, all interactions with objects (whether they are my own or come > from 3rd parties) should disallow the creation of dynamic properties. This > differs from your proposal in two important points: > 1. You cannot create dynamic properties on objects even if they come from > 3rd-party code you do not control. > 2. 3rd-party code may interact with your objects (and it's own) however > it likes. It is not affected by the disabling of dynamic properties in your > project code. > That's an interesting approach. I think it's conceptually a lot more complicated (and probably more complicated to implement, too) - the same object would behave in different ways in different contexts. There are also edge cases to define which the current proposal doesn't need to worry about, like stdClass, and objects which were created in one scope and manipulated in another: declare(strict_properties=0) { class Foo {} $foo = new Foo; $foo->bar = 42; } declare(strict_properties=1) { echo $foo; # Is $bar now 'defined', or do we only count the properties in the original class definition? } More importantly, you would have to check that third-party code was declaring the properties you needed before enabling it. For instance, a library might document that you should set `$handler->debug = true`, read that property internally, but never declare it; you'd then have to patch the library before you could run in strict_properties mode. It feels like at that point, we might as well just deprecate dynamic properties altogether - which I'm beginning to think is the best approach. To put it explicitly, what are the use cases where you'd turn such a flag off? > 1. The BC break section is not terribly clear due to the use of > "semi-reserved". I initially assumed that this was a contextual keyword > (i.e. only has special meaning immediately before "class") but apparently > this is a normal reserved keyword in the implementation (i.e. no classes, > functions, namespaces etc named "locked"). > Oops, I'll hold my hands up to not actually testing that. I think I took that wording from a comment in the parser, but probably didn't read it properly. 2. It is possible to break a reference by reassigning it to another > reference, like so: > > $null = null; > $this->prop =& $null; > unset($null); > > This is not quite as good as unsetting because it leaves behind an rc=1 > reference, but that would be the way to remove a reference without unset(). > Huh, cunning. :) Regards, -- Rowan Collins [IMSoP] --000000000000ff74f20583d08369--