Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104652 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23192 invoked from network); 11 Mar 2019 15:46:04 -0000 Received: from unknown (HELO mail-it1-f172.google.com) (209.85.166.172) by pb1.pair.com with SMTP; 11 Mar 2019 15:46:04 -0000 Received: by mail-it1-f172.google.com with SMTP id f186so12585745ita.0 for ; Mon, 11 Mar 2019 05:35:42 -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 :cc; bh=8C2tJKF5Zl1fhW0ww20HGBfN+rO+Cmp12xCVpjqNvyI=; b=aDILWDccaQ4KSs4aDz1JcvPzWnPusWhea0kiOZNJBPrNx90xyaVB79B/2stiPaR0U0 6bNAnTlXHKUfTW7+63asnX79gnQCiHZn6qOcz90FVuzTcTHqk8rxDMhx88HfMN6KsoHm dWdeHmjn1AHzSPCtgK7ldCA0AGj6fGHWoEOB9tnj9yzngr0BsctKnd5rRR67i4jsS0tt pz+Yz3RIEE/gKJqlDYLT7bqBZl/Xw15lpBRzcAszo1uwBs6PLeK9L84dgx5kzmzEdUZm oYdo22BEzZFd5nK4LjDoER+SCQmV0pU5ADdUCLf0uIinAP36hcyB5FGPuE4Wn1B2Tikz aspw== 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:cc; bh=8C2tJKF5Zl1fhW0ww20HGBfN+rO+Cmp12xCVpjqNvyI=; b=eBlf2iTDQ6nrb2cRfk+d+o9HSh4FvEdsRoaDGw/s5OR2wWtm/JBLK0mQ5hKSpyXOuB oeUU5HpPIGCwd5hJKjj8/gUGYXqJxxRV8n3zwNfI+lGRJU6yoxRhaVHXTvIR6abObxrG 9GJZ+5/w9QWjdbbG4kjVFBhOdQy9Bcdpm3Zsijx4qVrBzqWqn0FPJUFUMRXccD6S+pTO IzqayhNT9y8ZbcH66Y+bOptNjB8lVurLA0dCbope6Pk4ZYRRfdcp4TzGqBoGzaZS6OBX idTB5d2FT8RklMmeu8DQthqZjeYNfRz2DLHa4GC2ujroB6BmREHz9Mt+5jS1iCTyWPhP MEVw== X-Gm-Message-State: APjAAAVDi7Zx9o2naUMemwcxY+pzdkZtHib534fVcdHPpwo6K1xqMHtG hrbN7XypNP/bekAdT5fnV1Ga9IDeFrDTZ4IIHcU= X-Google-Smtp-Source: APXvYqwuxU6DidTG4yyss4Yz0DbXUwVCZ/7588CLiR9aEc5rslyEsh9QHH2RfhhgFhBXZicQ5NaCmkMcK2yscXMwiUg= X-Received: by 2002:a05:6638:285:: with SMTP id c5mr16727818jaq.36.1552307742633; Mon, 11 Mar 2019 05:35:42 -0700 (PDT) MIME-Version: 1.0 References: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> In-Reply-To: Date: Mon, 11 Mar 2019 13:35:26 +0100 Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000009500a70583d0cfc1" Subject: Re: [PHP-DEV] RFC: Locked Classes From: nikita.ppv@gmail.com (Nikita Popov) --0000000000009500a70583d0cfc1 Content-Type: text/plain; charset="UTF-8" On Mon, Mar 11, 2019 at 1:14 PM Rowan Collins wrote: > 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? > } > I'd expect it to be defined, especially as it allows interoperating with libraries that are missing property declarations and set dynamic properties (intentionally). 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? > You'd turn it off in the case you mentioned: A 3rd-party library that relies on dynamic properties. The idea is that you disable dynamic properties globally for your own code, but can opt back in for cases where they are necessary for some reason (most likely interoperability, but possibly also code doing weird Marco things). This allows you to single out some piece of code as "here be dragons", rather than keeping dragons as the default state :) Removing the ability to use dynamic properties (even excluding stdClass) is probably not feasible on a short timetime. However, I think that having a directory-scoped declare would also be useful for that, because it allows a more gradual migration. You can start with having strict_properties default to false and have interested parties opt-in. Then you can flip the default to true, while still giving people who rely heavily on it the ability to opt-out. Removal would be the final stage where the ability to opt-out goes away. Regarding optimizations that your RFC allows: In theory we could drop the properties_table member (8 bytes) for objects of locked classes. In practice this is probably not beneficial as access to the embedded property table would no longer be at a fixed offset. Nikita > 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] > --0000000000009500a70583d0cfc1--