Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104632 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90146 invoked from network); 10 Mar 2019 23:30:00 -0000 Received: from unknown (HELO mail-pg1-f178.google.com) (209.85.215.178) by pb1.pair.com with SMTP; 10 Mar 2019 23:30:00 -0000 Received: by mail-pg1-f178.google.com with SMTP id h11so2370408pgl.0 for ; Sun, 10 Mar 2019 13:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=trH1xTMHeWXH6BUJJgrkZhM5clLVJc/9MC1t9xDtx94=; b=k0v+VWitguxMs4DSJoH+vLtUYBD0EWECuYpS/CJYP98Z0v7EoOz6i/Rtnx6iAcF2r+ JjD3cPKgFg2Dk0dUAwnaXheWe+/Masi38K88AMsucwQLWRZftAYPVFzaORqkpzOJTG7W JvSclELaHe+yjgknRsMA7d4nH4iBAlvsfu3zydc1DI1Ki9YbfLhKWowcJ6Vde1AJzTlB u+PISaEW4hDTnqu1acnfVQjvzrk6c+Pw6d5GJA7FKPvTfqvz4SAOgZKWRtH5mlsfVw8a 3JeFFC0M0APx7V7PizPM5XllaP/pvNohgmZrQaMrf/FRR8zG0xZMs/CG3xrrcYPHhfhF 99OQ== 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=trH1xTMHeWXH6BUJJgrkZhM5clLVJc/9MC1t9xDtx94=; b=FQHscaQvqDfBFagYHCB55G/UoYFopQwWUxAUw8vVh1iOA7kq8kTf5pJRwJh7yCtw3N Q2eAttAclfNba+ZugDNdDMMDo8PJ8xok1Bb6O2V4NPdTBRhjyWApotnMYbcpXAkgswN9 pomZWANUgAHqLAYE1FAM5nVk7g5pFf3CFMlNPijLFcKa3cQsyHfB0qti1ifhqnvajbOj 8oopPy7o9f8xUX9x4lhnm1NaTMpTATRjfr2IUoA6mT6eKBeobsQKFVHGiFgImc0xFvBY 4/ri1L/ekXUyQXs0qTOHH+ng/L8anLMLTUxPN0h69ZmdcUwQgiGJRk+TRfOTJqEwI8nx 1Awg== X-Gm-Message-State: APjAAAUFGOzolBSo/ejj2joj3WsXk+XB3keoXeAqYhoDFes6pJihSIIK bD18GJko8dDe79mq7HXcQXc7I01+xlJjuQ40FahU4g== X-Google-Smtp-Source: APXvYqzQQTuw1usxiJjirU28tl3/sDZTvK8Kzv7SfGVrD2rOwdjMO9cJN5HNM7FUsFfSOi54G/yaVIcN7HXOODjRFmE= X-Received: by 2002:a63:d112:: with SMTP id k18mr27282817pgg.426.1552249168058; Sun, 10 Mar 2019 13:19:28 -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 20:19:17 +0000 Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000043f4c00583c32c3f" Subject: Re: [PHP-DEV] RFC: Locked Classes From: Danack@basereality.com (Dan Ackroyd) --00000000000043f4c00583c32c3f Content-Type: text/plain; charset="UTF-8" On Sun, 10 Mar 2019 at 18:35, Rowan Collins wrote: > > Hi all, > > - 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. I believe those two parts of the RFC are completely possible already in user-land with a trait similar to the one below. What would be the compelling case for making it be a keyword, rather than the user-land implementation that is already achievable? Also.....this seems to be a special case of an idea that has come up repeatedly, of allowing the concept of 'packages' with rules applied to all of the classes in a package e.g. * class Friendship which only allows access to certain methods to other classes in the same package. * strict enabled by default for a classes in a package. and now this RFC (or at least 2/3 of it) could be implemented by adding some traits by default to all classes in a package. Rather than adding a special case, I'd much rather we looked at providing the general case. cheers Dan Ack trait LockedClass { public function __set($name, $value) { throw new \Exception("Property [$name] doesn't exist for class [" . get_class($this) . "] so can't set it"); } public function __get($name) { throw new \Exception("Property [$name] doesn't exist for class [" . get_class($this) . "] so can't get it"); } } --00000000000043f4c00583c32c3f--