Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122615 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 F0A181AD8F6 for ; Mon, 11 Mar 2024 17:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710178403; bh=Ea+NfkSpI50Ml90fzVIqmLE1Ha4JbUfOcdgSo6E3myo=; h=In-Reply-To:References:Date:From:To:Subject:From; b=TqCKEOETO0Xj/qrFuNTU77ijTYNheBv/KFhJNbyu2q97M3SkeRXBhMuDr5U6sM6Hk 9f3rvhpmKv5UF6BSgmIiQtZTXBJIXk9bjVGRU816CpvwF0l7PgMl+k72mSt7dvc1Kz MHreWPLupO0my4dIPykh1Ohvd6j90nehmvT83Q+G0YIWYuZCx9kETeH5I63wAZuEge vW6ta0I/1UTTqoy+hqfWHxJrU4iTHATW46w1sS/ljKhd0wggvWdxGjRE6TqiiyeYAi f5SAO8BUNjUWGaNYYnruvcRIwwsKirn28iDsX9SZq4cOShxxMd8LqV81KV5DX+YMhg VspEnn6Jbx0lg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9B374180071 for ; Mon, 11 Mar 2024 17:33:22 +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_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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, 11 Mar 2024 17:33:22 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id BEB7A5C0039 for ; Mon, 11 Mar 2024 13:33:05 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 11 Mar 2024 13:33:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=1710178385; x=1710264785; bh=MWmk7bDmnwTH77hmtPK+w QQ1hm9ZELTw59RvTwBesYA=; b=tcdr9Lz46+VQfBz5PyPb5UQVGIOjiQIpZnFmv OzuM0xvKHhjwfBepAmfNTbdsPU9QqiDuzioKY5JKFD2b/c5xYP8SUg4G3dBaFEB8 yfm7IzeycvartXVrPuoVl/bLyJYPfpSfk6L2rUsaQZSjeDqEVJ7M2Lgk1mqT/F9F 15PG882ilextK/jGv7vEh1axtGgFbDEKpVuVnFPMxJ4v2VdZmA7hgmMwcfOf3iI5 pSI6PBICjizJDEJXmh7fwr0izqdrz0N6RNEYpNdwhUkaMPScN5IOx5MfYsQ1CFbC vNme2DhmXkzC67gaC/yhgKs4WZsTyORdTqhBKTb6+pj0c9Odg== 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=1710178385; x= 1710264785; bh=MWmk7bDmnwTH77hmtPK+wQQ1hm9ZELTw59RvTwBesYA=; b=T V+GnqY31TlM3n8xXbho5L3Fq9A9lCZyJljLlamStoPIjdvA+62EF6Sgc9BNwSLMi W27q0YkUK8M6l1c531OlM3EliGulafPJJ/eygw9sdFAnwdj4790bBljuEXGBfeWU /6ukq8TmSxtmOZiEgkKAzK+4+f/MZSjr9wectp16eJOn7jjTzYCK9NiVSykr9lzh qaa7hLaxXECnff9Jn7ECzgHxKXZ1edLEj6YXDoPH9AM/uIEV5F9ykxmjT4DubNaw cg2maQoL34qPwBN7r7TzqzHiarGX9yBXP7A6nvRzDDV0fkC5UZ2MQyaj7UN1yuvf YcXX3owLwK77B3sowhRmw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjedugddutddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 69FF81700093; Mon, 11 Mar 2024 13:33:05 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-251-g8332da0bf6-fm-20240305.001-g8332da0b Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <0efbb5ca-0b7f-4433-8afd-0dbb9cdb326f@app.fastmail.com> In-Reply-To: References: <84adc38a-210e-4f21-9145-0c99ae8c56f2@app.fastmail.com> Date: Mon, 11 Mar 2024 17:32:45 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Mar 11, 2024, at 4:58 PM, Micha=C5=82 Marcin Brzuchalski wrote: >> Hm, interesting. I'll have to check with Ilija on feasibility. My q= uestion is, how would it eliminate it? >>=20 >> Suppose we hypothetically have a "ReflectionPropertyWithHooks" reflec= tion object. It has those three extra methods on it. But that means $r= Object->getProperty() could return a ReflectionProperty or ReflectionPro= pertyWithHooks, and you don't know which it is. You'd have to do an ins= tanceof check to know which type of property it is, and thus what method= s are available. That doesn't seem any less clumsy (nor more, to be fai= r) than calling isVirtual().=20 > > It is similar when you work with ReflectionType or ReflectionEnum, you=20 > always need to match against a certain type to ensure the code will=20 > behave predictably. >=20 >> $rProp =3D $rObject->getProperty('foo', $obj); >> $rProp->getValue(); // works always. >>=20 >> if (!$rProp->isVirtual()) { >> $rProp->getRawValue(); // Works, may or may not be the same retur= n as getValue() >> } >>=20 >> vs. >>=20 >> if (!$rProp instanceof VirtualProperty) { >> $rProp->getRawValue(); // Works. >> } >>=20 >> That doesn't seem to be an improvement. If you omit the conditional,= you still need a catch one way or the other. It just changes what gets= thrown (an Exception vs an Error). What type of hierarchy were you thi= nking of that would help here? > > My thinking was like: > 1. if the property has hooks, only then calling getRawValue,=20 > setRawValue, or isVirtual make sense, > 2. if the property has no hooks and is static calling getRawValue, or=20 > setRawValue always throws because of "On a static property, this metho= d=20 > will always throw an error." > 3. if the property is "virtual", calling getRawValue, or setRawValue=20 > always throws an error, > 4. if the property is not "virtual", calling getValue, or setValue is=20 > safe and never throws, otherwise it may throw under some conditions=20 > related to certain hook presence. > > In conclusion, I thought that the presence of hooks introduces 3 new=20 > methods but some will always be thrown because of incorrect usage. > Normally, I'd model it with subtypes to completely avoid try-catch=20 > blocks for the cost of a simple instanceof check which I consider much=20 > cleaner for the reader than a bunch of try-catch blocks. Remember abou= t=20 > static analysis, each of them when checked will propose to handle=20 > possible exceptions. > > But as wrote before, I don't know how to model it well. Agreed, though I don't know how to model it either. :-) If someone can = figure out a way to do so before we go to a vote, we'll consider it. --Larry Garfield