Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104620 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54173 invoked from network); 10 Mar 2019 21:45:39 -0000 Received: from unknown (HELO mail-wm1-f49.google.com) (209.85.128.49) by pb1.pair.com with SMTP; 10 Mar 2019 21:45:39 -0000 Received: by mail-wm1-f49.google.com with SMTP id f65so2244972wma.2 for ; Sun, 10 Mar 2019 11:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=7A+/e2SjEwnYEfvSOAx89ALgPCO1ZcDRwPPdYuo8+zA=; b=CYVUZyVVbu7fgH3fhvrlBNN5HOWs8NxNn6S9l2jeINupC6D4DvXtbqVf105rAQ4kB3 V5R805QyVo+rAOZc4kbX7Jc8vJyvb3OFzgx4n7/Ot1EH2+QouqCI5abrKNx3ibEnxG/6 pynVDgZXll765ejpQiIjfGEGhmBkb0HrLzh0U89F41TrfIlHDQ5AWSFaY0Sra1IKQSZn VL2VqzRiznjCb7j9j9iubrKpqnV3T5ddjj75o9aSQmYyMb+9D99ZrJnsc8mx2p5/EbqE g1ZkbegoK91qRlwBOmxxlla5i2lsqUnz6z6oYpvXTFlow1yVCfaZhiU7pdy/XICaYxbu uceg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=7A+/e2SjEwnYEfvSOAx89ALgPCO1ZcDRwPPdYuo8+zA=; b=NpseKHgfKn2vxCSQPFraJaE6lNfeMwgCh2+4g+dYshRwTdi9MIpj796qsk4znyyhPc VG2dxS4UGV58nPRRUez89KnBimkuqwUrQ++4OEOeoJzpZgF1HbUH40Lv+uVRsm222HW4 dNChKvboukSFWQVHX3E+ZPJRHGGcoqaaTipxfsA1spbsyA5WyNr71ZNzn2XnOzsuuTHj cXBMHDl/z+h8e5jXGqbwpeZkoO3Hp7K36c2c41THC9LYzCDDlBxxkItgCJ+S1NLX9TC9 hGZ8K/4PCCbkoGulZdi6nl/njap6usL7zihZ4hxjpap6eBGNNcYV3hqldYQWHsNbWT7n AglQ== X-Gm-Message-State: APjAAAVGzZxPR1gJjFwZG+89YwoUP62J9DeApNIEymF3nNfRb9TQPvEx SBCYuwMK10AFTxVjVCcGthncH4S4 X-Google-Smtp-Source: APXvYqwniAwVutS61XbSR1HTHH7MzL+jtysvEAp3uhHf+8NmILbTRx+60bblUPOrN4Vx+Dt7+4sIIg== X-Received: by 2002:a7b:cf27:: with SMTP id m7mr14910582wmg.80.1552242904830; Sun, 10 Mar 2019 11:35:04 -0700 (PDT) Received: from [192.168.0.16] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id s5sm8875234wra.77.2019.03.10.11.35.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Mar 2019 11:35:03 -0700 (PDT) To: PHP Internals Message-ID: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> Date: Sun, 10 Mar 2019 18:35:03 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: RFC: Locked Classes From: rowan.collins@gmail.com (Rowan Collins) 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]