Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104622 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60428 invoked from network); 10 Mar 2019 22:02:43 -0000 Received: from unknown (HELO mail-it1-f180.google.com) (209.85.166.180) by pb1.pair.com with SMTP; 10 Mar 2019 22:02:43 -0000 Received: by mail-it1-f180.google.com with SMTP id z124so3930012itc.2 for ; Sun, 10 Mar 2019 11:52:10 -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=udc5TOnrlpZHt8713n/KhOmng36gq5sQSwhNmMnVJlw=; b=DQglSlYmrK3NHEOI9Smlj0HtFXuvG0kJDRtX6ujNpSk/y3Pe+aV4KJLru1yD+kVsjk Cnqh4s+4Vayq53bhccMmL2fUz4yvsspZ7mgeE6N/eqohrdb89QnpLtO4JfMRcw4onzK4 I/KWVIkhu1nvKPWMrRULz75JWJiPjfy9TCNiIxa/fJuP0YZjDKQ6TVmE1PnmwR5SId5/ lhILikHveQFPMYP4ceOCP74A5L2sgF8XzQahCHZtjkN804EPeBjxpUXJqqckHGWrHE90 n9q5OFmLfR/Q5CBPhzeJwVkQNZ8ijnOc8YV4Vkk6e/UqlDcs/7TCNzMN+RT9y9konI3b A/YA== 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=udc5TOnrlpZHt8713n/KhOmng36gq5sQSwhNmMnVJlw=; b=kTAkts8FW5rhZDj6RisB4H9TonaAELQ65Hr5EGsyX0c3r6bTpTtswuL0w4bdR3T8IC e35xdAoaOmSOcANN9/Sbel6epzjmleBZSwVbCx6ZQs0uy99FlLCknmfxAH38vioWlyTB eNc14CWHeKDRpyt5PEBhET+oXPouSgRjvhsiCCHfp+4LDXL7ea+j5Y//h4HmL/To2ocQ 6O4+03pU7VloZPLYBGAUsHuEvNGZP95PqaP34s6BBk7pdY8hXUIeHn8EKAasZ7Is6mB2 PL56A1i/1gnCq1nkSAgB3Yytj+e05UBGp3lpfZKlhb+1A1vM25dpa7WurePVspAklxIY Vhsw== X-Gm-Message-State: APjAAAWXPrbvuuzF6MjubTdyU+zlvxsQrRZnK1X01LvRYtWpWj/S3FpR 1mMbWzepxXGfOUE/CjDawpSFPN03kkWAo/tVhv8= X-Google-Smtp-Source: APXvYqyu5RroTk9ps2U2JqrJufziWc0NO2Gjr4y/w4oSZLkAqSl6D4uuR3vRBd3GP4NKH7Zwhbv1Ng+kLkgQeR9INGc= X-Received: by 2002:a24:77c2:: with SMTP id g185mr14334826itc.31.1552243930437; Sun, 10 Mar 2019 11:52:10 -0700 (PDT) MIME-Version: 1.0 References: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> In-Reply-To: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> Date: Sun, 10 Mar 2019 19:51:57 +0100 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000001424fe0583c1f469" Subject: Re: [PHP-DEV] RFC: Locked Classes From: ocramius@gmail.com (Marco Pivetta) --0000000000001424fe0583c1f469 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Rowan, Overall good idea, except that I disagree with the `unset()` being disabled: that bit is strictly required for lazy-loading purposes, and mostly harmless for userland ("normal" people don't do it, libraries do it)= . Besides that (blocker for me), if this RFC would be enforced in my coding standards of choice =F0=9F=91=8D Does anybody know if this has potential for engine optimizations? On Sun, 10 Mar 2019, 19:35 Rowan Collins, wrote: > Hi all, > > I'd like to present a new RFC for "locked classes": classes which > restrict dynamically adding or removing properties from their instances. > > While it can be useful, the ability to set an object property which is > not part of the class definition can also lead to subtle bugs. Banning > this for all objects would be a significant and painful breaking change, > so I propose instead the option to mark a particular class with a new > keyword, "locked". > > An instance of a locked class behaves like any other object, except that: > > - Attempting to set a property on the instance which was not declared in > the class (or inherited from one of its parent classes) will throw an > error, and the instance will not be modified. > - Attempting to read a property on the instance which was not declared > (or inherited) will throw an error, rather than raising a Notice and > evaluating to null. > - Attempting to call unset() on any property of the instance will throw > an error, and the instance will not be modified. > > Note that ECMAScript / JavaScript includes a similar feature, called > "sealed objects". However, the proposed modifier applies to classes, and > "sealed class" has a different meaning elsewhere (e.g. C#, Kotlin), so > I've chosen "locked class" to avoid confusion. > > For further details and examples, please check the RFC at > https://wiki.php.net/rfc/locked-classes and the tests in the draft > implementation at https://github.com/php/php-src/pull/3931 > > Regards, > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0000000000001424fe0583c1f469--