Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123691 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 C304D1A009C for ; Thu, 20 Jun 2024 08:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718873475; bh=3pdVVADk/YdWQ77Okbe4QJIxxkpYnAdQo8SYc+2hyfM=; h=References:In-Reply-To:From:Date:Subject:To:From; b=d8LbXhOiR8Rkzzwitl1P92oMAyWpNCJSgEyAxPYvoo2D24yvmaIU/wA2jvoceyFOK 9TdeDkCLdI2AX2UYkvFCY8PyVquUeW96FkA+XSz0loi59a7sH55dKuWbpANp0xOPj2 jdNUwKUCV5dIkBkJ/TJvqJf+Esu/On0a6dWccI0n1tfMw7R/WUcSvLWVGoI8DuDYGl ZDBNlI38maIOtxJvdCg+TypR5E9U09KZNHXx06PEX8ct33zJVrkso/5IVIdfvVGIpM qYfQheGWRaI6ftI9aEPnvUPsDsoa+cZqaVPtHWk8lNFEwHDnMbKTqQ8YJXFpu8RhYl 87ha7BkMeliQg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7763618005C for ; Thu, 20 Jun 2024 08:51:14 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, 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 mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Thu, 20 Jun 2024 08:51:14 +0000 (UTC) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52bc27cfb14so807499e87.0 for ; Thu, 20 Jun 2024 01:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718873399; x=1719478199; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=fTSd34r7FgD1S4UbGLX6gAq8MskNxbzeCSBz19KNZeY=; b=hls/OLq3OEzS8Z2YH82iVBMcouKK1X3YDNszOS9ps4n3/Q8OmJsSKLodH2udTExtxw izR8DF18RY5kIgKOdhi9ln+7MH9pWLqamYzNgFer68+sM2tj3XUtVqAS71LDDUB08kda 3VWxxrqu8xE2ZvoRjJSYTGVTzxbtmzB3yjXzj0HXwjYSmYNscmQ4SsvXtC7kIzWe9ueR 398VOZKSY1Nyn/bYTOeIeVlT/tubY+DzESfH8kr8pgfEs8BrisCjG9ieKjAC/ff6GXW1 XKsO0hBaXawcv73HXVcZT9dgnAXe+5C7Qxu0BPSJYxZaDxAoOMfUmysAdVoqgihPtXTx rcIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873399; x=1719478199; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fTSd34r7FgD1S4UbGLX6gAq8MskNxbzeCSBz19KNZeY=; b=NZHWakt6mPKfNNvnS+ixSSzfyj9mKeCXne3WT3RQoIR+oDyka7Lyhsb7GkDZEYBYl8 5YO4j2gp0W56xjbStqpUAZQJtCUmevh9n6Exmg67vAH61IDNWchHEzZhG6HaX4zGOFDD l+t0+yEKtMH/ARSQFIR3nwCKfT6ItAmQlo/hx4Jq1qx+pQa/vh/AMEW7zG8FWOXtRMma PZWz/gIhLv6RhRtHtWu5qCAn8qCs2fS7W1H3R6estSJKElMl62+HfdiC+crrhCeK9PrI cHd7/fRtWQEg/a78wj1vuxHF0BBcf7xGQX6J8q9r8596DXrHtvLDRPcqq6rukyktE/yK 6cGw== X-Forwarded-Encrypted: i=1; AJvYcCU6DkZfzxHPjQE1mWWhF5exRzfs+eGYtToeoyPHLeormN92IrI5qXenOfCC1Cnqmj6tljNPZXzZYplYlVQ2NM2X77YDzgOeQQ== X-Gm-Message-State: AOJu0YxddcmYYcBB0A35jFhvYZpdgmT7n2INJjXhKcn7Kks9G5qRc5f0 1Ock8+4KfxbpidG+LHBXjDR5mpYSvB8h+9w8htop74mec3eWwpqTcEtFKQZi/O2OH1sVwU5sXOc eRAklB3VHMgNWcyBXt4jNaXFOSbdQseZaz+w= X-Google-Smtp-Source: AGHT+IGCwh3VaZbMPer/PaPHH0lodMHBZt2tlHpK6vtQ6Se1fBqYAf+DkSVqep8Ts+0HGgmsGdkYHPlMUBz8LIeBFjI= X-Received: by 2002:a05:6512:124a:b0:52c:ab21:7c05 with SMTP id 2adb3069b0e04-52ccaa599b7mr4268997e87.67.1718873398473; Thu, 20 Jun 2024 01:49:58 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <1118bbcd-a7b4-47bf-bf35-1a36ab4628e1@bastelstu.be> <8fc1969d-5f21-400d-a3ae-aee5d741a81d@app.fastmail.com> In-Reply-To: <8fc1969d-5f21-400d-a3ae-aee5d741a81d@app.fastmail.com> Date: Thu, 20 Jun 2024 10:49:46 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000547cb6061b4e6600" From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000547cb6061b4e6600 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le mar. 18 juin 2024 =C3=A0 22:59, Larry Garfield = a =C3=A9crit : > On Tue, Jun 18, 2024, at 5:45 PM, Arnaud Le Blanc wrote: > > Hi Larry, > > > > Following your feedback we propose to amend the API as follows: > > > > ``` > > class ReflectionClass > > { > > public function newLazyProxy(callable $factory, int $options): > object {} > > > > public function newLazyGhost(callable $initializer, int $options): > object {} > > > > public function resetAsLazyProxy(object $object, callable > > $factory, int $options): void {} > > > > public function resetAsLazyGhost(object $object, callable > > $initializer, int $options): void {} > > > > public function initialize(object $object): object {} > > > > public function isInitialized(object $object): bool {} > > > > // existing methods > > } > > > > class ReflectionProperty > > { > > public function setRawValueWithoutInitialization(object $object, > > mixed $value): void {} > > > > public function skipInitialization(object $object): void {} > > > > // existing methods > > } > > ``` > > > > Comments / rationale: > > - Adding methods on ReflectionClass instead of ReflectionObject is > > better from a performance point of view, as mentioned earlier > > - Keeping the word "Lazy" in method names is clearer, especially for > > "newLazyProxy" as a the "Proxy" pattern has many uses-cases that are > > not related to laziness. However we removed the word "Instance" to > > make the names shorter. > > - We have renamed "make" methods to "reset", following your feedback > > about the word "make". It should better convey the behavior of these > > methods, and clarify that it's modifying the object in-place as well > > as resetting its state > > - setRawValueWithoutInitialization() has the same behavior as > > setRawValue() (from the hooks RFC), except it doesn't trigger > > initialization > > - Renamed $initializer to $factory for proxy methods > > > > WDYT? > > > > Best Regards, > > Arnaud > > Oh, that looks *so* much more self-explanatory and readable. I love it. > Thanks! (Looks like the RFC text hasn't been updated yet.) > Happy you like it so much! The text of the RFC is now up to date. Note that we renamed ReflectionProperty::skipInitialization() and setRawValueWithoutInitialization() to skipLazyInitialization() and setRawValueWithoutLazyInitialization() after we realized that ReflectionProperty already has an isInitialized() method for something quite different. While Arnaud works on moving the code to the updated API, are there more comments on this RFC before we consider opening the vote? Cheers, Nicolas --000000000000547cb6061b4e6600 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
Le=C2=A0mar. 18 juin 2024 =C3=A0=C2= =A022:59, Larry Garfield <larr= y@garfieldtech.com> a =C3=A9crit=C2=A0:
On Tue, Jun 18, 2024, at 5:45 PM, Arnaud L= e Blanc wrote:
> Hi Larry,
>
> Following your feedback we propose to amend the API as follows:
>
> ```
> class ReflectionClass
> {
>=C2=A0 =C2=A0 =C2=A0public function newLazyProxy(callable $factory, int= $options): object {}
>
>=C2=A0 =C2=A0 =C2=A0public function newLazyGhost(callable $initializer,= int $options): object {}
>
>=C2=A0 =C2=A0 =C2=A0public function resetAsLazyProxy(object $object, ca= llable
> $factory, int $options): void {}
>
>=C2=A0 =C2=A0 =C2=A0public function resetAsLazyGhost(object $object, ca= llable
> $initializer, int $options): void {}
>
>=C2=A0 =C2=A0 =C2=A0public function initialize(object $object): object = {}
>
>=C2=A0 =C2=A0 =C2=A0public function isInitialized(object $object): bool= {}
>
>=C2=A0 =C2=A0 =C2=A0// existing methods
> }
>
> class ReflectionProperty
> {
>=C2=A0 =C2=A0 =C2=A0public function setRawValueWithoutInitialization(ob= ject $object,
> mixed $value): void {}
>
>=C2=A0 =C2=A0 =C2=A0public function skipInitialization(object $object):= void {}
>
>=C2=A0 =C2=A0 =C2=A0// existing methods
> }
> ```
>
> Comments / rationale:
> - Adding methods on ReflectionClass instead of ReflectionObject is
> better from a performance point of view, as mentioned earlier
> - Keeping the word "Lazy" in method names is clearer, especi= ally for
> "newLazyProxy" as a the "Proxy" pattern has many u= ses-cases that are
> not related to laziness. However we removed the word "Instance&qu= ot; to
> make the names shorter.
> - We have renamed "make" methods to "reset", follo= wing your feedback
> about the word "make". It should better convey the behavior = of these
> methods, and clarify that it's modifying the object in-place as we= ll
> as resetting its state
> - setRawValueWithoutInitialization() has the same behavior as
> setRawValue() (from the hooks RFC), except it doesn't trigger
> initialization
> - Renamed $initializer to $factory for proxy methods
>
> WDYT?
>
> Best Regards,
> Arnaud

Oh, that looks *so* much more self-explanatory and readable.=C2=A0 I love i= t.=C2=A0 Thanks!=C2=A0 (Looks like the RFC text hasn't been updated yet= .)

Happy you like it so much! The text = of the RFC is now up to date. Note that we renamed ReflectionProperty::skip= Initialization() and setRawValueWithoutInitialization() to skipLazyInitiali= zation() and setRawValueWithoutLazyInitialization() after we realized that = ReflectionProperty already has an isInitialized() method for something quit= e different.

While Arnaud works on moving the code= to the updated API, are there more comments on this RFC before we consider= opening the vote?

Cheers,
Nicolas
--000000000000547cb6061b4e6600--