Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104688 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2997 invoked from network); 13 Mar 2019 02:43:20 -0000 Received: from unknown (HELO mail-wm1-f46.google.com) (209.85.128.46) by pb1.pair.com with SMTP; 13 Mar 2019 02:43:20 -0000 Received: by mail-wm1-f46.google.com with SMTP id f3so31030wmj.4 for ; Tue, 12 Mar 2019 16:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=L7K2G7hv63WD+E8jtRHQi8zjAheQ+oCp1qBtsHAtpGk=; b=MMOH0rEnKS5IN9LU6X8WXC4SIh0pWQXuhp7pMfAnRjHgAthirKFLFd10LvwCmtrqUU i3JxzcE6loKmiNn4DKM0VpJhMfQjW+DObXu15CwJ7d31obn+YQdn47o95S3QwG3LFYta ie6konsClTgBSvPhsYUjh/XxuPguwi0CsY+JZMOjYM7D2M/NcC+SD0VBmD+izge0KhAN jjMTnPQwogY1y8Iy5J0dd3eGvuKpjzU/9PWlmIoLGcSWCZ01mONwt8HfqY7FeITVVB6U EteOHTECAShc2/mjWTFL5QTVxJuSStvGnucmK2/h8CT0JJZGdggWqeVaQl9PL3nXOwtk pWyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=L7K2G7hv63WD+E8jtRHQi8zjAheQ+oCp1qBtsHAtpGk=; b=RgcvGCCB237xBVFipkr540/i8xR7W/2hwSnh4fNouO9qyzOw/B/ZYD4rOa3d859dyD xFFlfL5ec6Zf6Ukp/ug9i09djSWOgC0zMMhqJIaNzkQkGlWfa2udNRWy38sfUL5UxEMj L0EnJX0g5EtGtoVacZFDhRVOENNPp1HNramzIWA5kAfCA+2imtvU7VQQmHdhFNv7UmLt TBaTR28bCfPE7TIrfZZJJEDVJMnmqqmPFyC0Ud88ZZlxt5Yq0oaVHUsP8JZj01xU0M1+ ZEsoaiaX3SheVvk4Oi6tiIN21CgNNoGknPlEEn7mmUWrXgWJwsR+fgoOamV1/gCjb/Zh WENg== X-Gm-Message-State: APjAAAV8FeIZluQB0UYEoXl+iLVdDEIqisOCV+nNCdzGqA8bZoh2d7IH J5THzPOFGX4bH3xM76aesng0Lk9t X-Google-Smtp-Source: APXvYqy5R5W1LOoNp4v3sK6vfuDpUhnescXTzuAYLoolAAOuZVcaBsRKr4PTKkO5OnjpaqaEx+QO7w== X-Received: by 2002:a1c:b40b:: with SMTP id d11mr176791wmf.80.1552433599066; Tue, 12 Mar 2019 16:33:19 -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 o12sm31263412wre.0.2019.03.12.16.33.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 16:33:18 -0700 (PDT) To: PHP Internals References: <2c497732-96f8-3ef0-bc18-912220fbff4d@gmail.com> Message-ID: <51049996-83bf-f59c-50bb-6b664ae4ed12@gmail.com> Date: Tue, 12 Mar 2019 23:33:16 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC: Locked Classes From: rowan.collins@gmail.com (Rowan Collins) On 12/03/2019 21:40, Stanislav Malyshev wrote: > Isn't it just: > trait Locked { > public function __set($name, $value) { > throw new RuntimeException("Property $name not declared!"); > } > public function __get($name) { > throw new RuntimeException("Property $name not declared!"); > } > public function __unset($name) { > throw new RuntimeException("Property $name not declared!"); > } > } Almost... Magic methods are run both for undefined properties and out-of-scope ones, so at the very least this leads to unhelpful or vague error messages. It also doesn't handle unset in the same way as the current RFC, because it won't affect unsetting a property that was previously defined (although that part of the RFC is slightly controversial, it seems). There may be other edge cases it doesn't handle the same way an internal implementation would, as well, I'm not sure. It's certainly not a major saving over hacking it together in userland, but nor is it a major weight to add it to the language. I think having a well-thought-out implementation built in (either the one in the current RFC, or a declare directive as has been suggested elsewhere) would encourage people to use it, and generally be more user-friendly. Regards, -- Rowan Collins [IMSoP]