Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122509 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 8B61D1AD8F6 for ; Mon, 26 Feb 2024 22:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708987589; bh=MRqqoH6S+wccznU0XWSaU4rGaERXXFxyjTNY6uRHohU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=QYVPpJBJfaJHLF6SLZidIv9JUTPP3itF/DBGFf3itzTpzGWPqFkMm2k8PAmTDhJua vfj/aVNM5ojCoYqhbToeFXHVkhrMqvg5Soc7yeattwXGMckZtXGsO8KBm4rMyy0oAy rx4GVucF4WeZV+csY/KAl7Hoz+Af7yS+61UvTHNQtaBmcvPS+X9CTyqKt00D/u83VC /qzt6sVnDrmtLbHsKF9AeXxN1ZaRkZr6Hfwf+RG/QwTWxwShLbdDgtIUi9UKUYyw07 dIYeBS+VklFykT1ITbXDZ/mLqV8YhFGNxj0TXh/jizBzmmrI/ysufSyr5fkyt55LDh pZDbnkY2jKX4g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 28C0C18003F for ; Mon, 26 Feb 2024 22:46:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 26 Feb 2024 14:46:26 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 75D033200A17 for ; Mon, 26 Feb 2024 17:46:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 26 Feb 2024 17:46:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1708987575; x=1709073975; bh=s9LO/yXaRNRxzsoF98A4VsxXtBmko6rY8ykKrUxPmAQ=; b= FgceT0OTb/veZOsYtWPsNddXvqzrXRDNRjhEiPNO3MVlAxpt4OFmVxPaIC5AU/xL 4q022mw3kvujdgYNOLmfmXWny/4Y1cbgVEXc3iS9FFJnwF7HwnK985kpmU68BULy NY4f3I5ua4rEASS1aqlkQRzrWeWvgKgSQ9sWavxVNDKJPbVlOXTAwuuEtXtqmqUJ 6G6+boXoBTScZPkggJ8K7RmSa3gyKGKi4Ksl1C12NsEWNhrP13l8E382K0OIUgzC zad8xq1uDMnArNzQ6XJb3dJ5nTOSCFiO+nRxQLhKPmKe33CDynsXdDXCRTW6KICo 0nnueH84GYx6dLfli9mBXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1708987575; x= 1709073975; bh=s9LO/yXaRNRxzsoF98A4VsxXtBmko6rY8ykKrUxPmAQ=; b=f 4ecYaMlMDN3XTHYrCssGst0ftu+em9XkqxqXxiZsFaPrsdLU2Ci4F4FtU7G75x7a bE9YA812ox9gP0atMSTbKa91Vh9ATBF4EQpViTzJg5PiCEx72GMpG/bUOH4N4PLF 8a4A6jftAk8xxlmmGtcI/DBoNDjVkMyRSrRCd6GmGgVF4jYZWYC2OqldwM3Axc1C ea3wf04A3FlntKuwNftLHtwO4EXgQ4EHsgLN+OB72jtXWFgKKMVh16PFcO9fPypI kUYuVeXw90ooK4k7trp5bmYHOWQxn6ElwXiTKdgNm0h4pt8lw9JDHEOoGsz8atIn rJwK94BqDTOuUI0Dc0eqw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeefgddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekre dttddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcu oehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepff ekveduffduvdehjedvfeekleeftddugeefheejudehgeeiudffgeeggeevfeehnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrph hhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 26 Feb 2024 17:46:15 -0500 (EST) Message-ID: <876aff9f-3eae-4d2d-8e3f-30dfbbeed49c@rwec.co.uk> Date: Mon, 26 Feb 2024 22:46:13 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Language: en-GB To: internals@lists.php.net References: <790b5b4e-f51b-4050-a12a-5fa903d0568f@app.fastmail.com> <52C6F501-8E23-42D7-8541-88A22AD79375@koalephant.com> <36e90d8d-d275-4ce9-9dd9-1e2422c6d3a9@app.fastmail.com> <2fdf1933-b51c-40cc-8d02-31899b96c71c@genkgo.nl> <95e93cb9-3ab0-4cf3-8ec5-83e74c9dd607@genkgo.nl> In-Reply-To: <95e93cb9-3ab0-4cf3-8ec5-83e74c9dd607@genkgo.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 26/02/2024 20:21, Frederik Bosch wrote: > I do note that $this->propName might suggest that the backing value is > accessible from other locations than only the property's own get/set > methods, because of $this usage. Yes, I actually stumbled over that confusion when I was writing some of the examples in my lengthy e-mail in this thread. As I understand it, this would work: public string $foo {     get { $this->foo ??= 0; $this->foo++; return $this->foo; }     set { throw new Exception; } } Outside the hooks, trying to write to $this->foo would throw the exception, because it refers to the hooked property as a whole; but inside, the same name refers to something different, which isn't accessible anywhere else. Now that I've looked more at how Kotlin uses "field", I understand why it makes sense - it's not an alias for the property itself, but the way to access a "backing store" which has no other name. Using $this->foo as the name is tempting if you think of hooks as happening "on top of" the "real" property; but that would be a different feature, like Switft's "property observers" (willSet and didSet). What's really happening is that we're declaring two things at once, and giving them the same name; almost as if we'd written this: public string $foo {     get { static $_foo; $_foo ??= 0; $_foo++; return $_foo; }     set { throw new Exception; } } Kotlin's "field" is kind of the equivalent of that "static $_foo" > Regarding returning void=null, this is something that IDE and static > analyzers already pick-up as an error. I think being stricter on that > in this RFC would actually make sense, and treat void not as null. > What would happen if a setter contained both "return 42;" and "return;"? The latter is explicitly allowed in "void" functions, but is also allowed in a non-void function as meaning "return null;" > And why yield is magic, I do not get that. The word and the expression > actually expresses that something is, well, yielded. > But yielded to where? My mental model of "return to set" is that this: public string $name { set($value) { $x = something($value); return $x + 1; } } Is effectively: private function _name_set($value) { $x = something($value); return $x + 1; } } plus: $this->name = $this->_name_set($value); With "yield", I can't picture that simple translation; the "magic" is whatever translates the "yield" keyword into "$this->name =" I would file it with the type widening in the RFC: seems kind of cool, but probably isn't worth the added complexity. Regards, -- Rowan Tommins [IMSoP]