Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123522 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 F2A9B1A009C for ; Wed, 5 Jun 2024 17:41:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717609362; bh=L0xCsvrMOgMXeFMZp6qgudJNnHKedU+ek7vyfoN1cd0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=W6i8t9s9vD44wcwzjSKLg1FUl2o6medu6i7oEth0GXKMR6yyZkhWUmsIyUOCU68ow 6MaGNaucjN+o4LtUGwLIrzFCscqFan16G3qWS87UTzPsaVkzdw30IldKyeq2ZxWZlU a54kGF7xrti/5fr09tkX4DSQx9D6cSDkmF0x8sdyE/knZMp1nQ4xYRkHxrVnmrQFyc 8irmp+DE83DnHyPLh10wVAdZpUmufjQq89qZvuhmIHeYZwCU1bU8bQBN77VIzO6ZC3 4zsLB3bcHGnRLqDZ9nkEZVtj5SxswrNf8TcAjk+X8IkrM0DgACuZL1eFzJGRc8Lx95 V0kd40lr0CJWw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5207D180510 for ; Wed, 5 Jun 2024 17:42:40 +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, 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-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 ; Wed, 5 Jun 2024 17:42:39 +0000 (UTC) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2e95a1f9c53so1106831fa.0 for ; Wed, 05 Jun 2024 10:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717609294; x=1718214094; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=L0xCsvrMOgMXeFMZp6qgudJNnHKedU+ek7vyfoN1cd0=; b=JExu2DHl9Ahwuw1Y7V8tVIeKGTlaDcAoB3NW1SDntqpYxUkPslK2MaaNBbPAdHHRgT J0N7KU23ajEA1LbYMM2Rc8XR5ONf/CgmlUelnD1vCE8NCJsPBXssPjhHjOU2bOU9YYkm 3ZnLYV9fWKZPE9Gx/M9S/1UsZlr1+hzBsVICUrsdHKlaG5ar9/KjLnTzk48vw9hlr1Rh sdg4OvE/4WK63gyJZOwjT7C+TNcbAisHG2hv02ssebz1Ng7XDRLF9sTM36fAeSY6BUIn hreox8jM+H9Xvhy+orxgwTWzMUje/SAc+9jP1p7I9m25VSECPKSltzv96LWjIFU25g3q Wrcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717609294; x=1718214094; h=content-transfer-encoding:cc: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=L0xCsvrMOgMXeFMZp6qgudJNnHKedU+ek7vyfoN1cd0=; b=wKANQTWxKLsOjEMYR8fZ5vPdM/+TYsYLwmVeGid1nfWx1/cmYNKNS/iRv4mKOooTbe RY8KjWGsAcnm5E2zISrxOmfLyjNCvMYvXl1pSsgapJYPPWq+AciiQhnKDwXEDMEPKAs0 csurAgvl57fey/4FeN8rm6JULLBXE0Nq8aepsB87LZgY2aC9s/uMdK2A2G+WNOMLQnQA od9IxF90YDidJMcI02eoS9LnVbtfUwRJIptAQspLwElEvdywviCPmwftiOEf1pNOBVvt WhAmKyE+vNl4tQ0DoS9fWEuNSX2xOoQdzNAVPSOaNhvGFC82E7O4e9vwnMfLTtmfiHTR /dsw== X-Forwarded-Encrypted: i=1; AJvYcCWFLvGPvA9HZTdgJUSKCMq4eOkCjf/nZvqq7FmQs30Ozu0pZylyYNDIWEvfAQQFHTFjlQ4XP3G6j0p71rozLVp9GPxIsTjPmA== X-Gm-Message-State: AOJu0YzSBcbJ7MRyfSqAlcsuEuKgI6QoIg2tOOdYePOuoQ1CdfkVejOQ IvVuLb8vLFUePPf2zEUuG48Sp5FNeApo8/dqVpenx56Ly1lao2mH1hoFn9teIYojITUjpQxF9dT wYoagflWiDcT7tdC0Bg+rm5F8Yiw= X-Google-Smtp-Source: AGHT+IG+ItgR5FbYdrcGYhXxv4ptn3G5JilOZ1auivHhkDln7Owux6TyUQ65nKJv74f3L3kjvYgLC9JKT681t2sEuSA= X-Received: by 2002:a2e:b74b:0:b0:2e6:ccfd:fae5 with SMTP id 38308e7fff4ca-2eac79bacd4mr17134361fa.4.1717609293293; Wed, 05 Jun 2024 10:41:33 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 5 Jun 2024 19:41:20 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: Nicolas Grekas Cc: =?UTF-8?Q?Tim_D=C3=BCsterhus?= , Valentin Udaltsov , PHP Internals List , Arnaud Le Blanc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Wed, Jun 5, 2024 at 6:58=E2=80=AFPM Nicolas Grekas wrote: > > Hi Tim, > > Thanks for the detailed feedback. Arnaud already answered most of your qu= estions, here is the remaining one: > >> On 6/4/24 14:28, Nicolas Grekas wrote: >> > Please find all the details here: >> > https://wiki.php.net/rfc/lazy-objects >> > >> > We look forward to your thoughts and feedback. >> >> I've gave the RFC three or four passes and I'm not quite sure if I >> follow everything, here's a list of some questions / remarks that came >> to mind, roughly ordered by the order of things appearing in the RFC. >> >> - "been tested successfully on the Doctrine and on the Symfony projects" >> >> Is there a PoC patch showcasing how the code would change / be >> simplified for those pre-existing codebases? > > > Yes! > See https://github.com/nicolas-grekas/symfony/pull/44 for Symfony. All th= e complex code is gone \o/ > And if anyone is wondering: No, we're not moving this complexity into the= engine. As Arnaud wrote somewhere: Implementation in core is simple compar= ed to userland as we are at the right level of abstraction. No code gen, no= edge cases with relative type hints, visibility, readonly, hooks, etc. We = get more consistent and transparent behavior as well compared to userland i= mpl. > > For Doctrine, the URL is https://github.com/nicolas-grekas/doctrine-orm/p= ull/6 for now, with the most important line being the removal of the symfon= y/var-exporter dependency. > > After yours and Valentin's feedback, we're considering an updated API tha= t would provide the same capabilities but that might be more consensual. > > The RFC isn't updated but below is what we have in our drafts. Let me kno= w what you think already if you want (otherwise, let us work on the updated= implementation/RFC and we'll let you know about them ASAP). > > Nicolas > PS: I understand that the concepts in the RFC might be difficult to grasp= . They were certainly challenging for me to summarize. I would happily acce= pt any help to improve the wording if anyone is willing. > > > class ReflectionLazyClass extends ReflectionClass > { > public int const SKIP_INITIALIZATION_ON_SERIALIZE =3D 1; > public int const SKIP_DESTRUCTOR =3D 2; > > public function __construct(object|string $objectOrClass); > > public function newLazyGhostInstance(callable $initializer, int $options = =3D 0): object; > public function newLazyProxyInstance(callable $initializer, int $options = =3D 0): object; > > public function makeInstanceLazyGhost(object $object, callable $initializ= er, int $options =3D 0): void; > public function makeInstanceLazyProxy(object $object, callable $initializ= er, int $options =3D 0): void; > public static function isInitialized(object $instance): bool; > /** > * Initializes a lazy object (no-op if the object is already initialized.) > * > * The backing object is returned, which can be another instance than the = lazy object when the virtual strategy is used. > */ > public function initialize(object $object, bool $skipInitializer =3D fals= e): object; > /** > * Marks a property as *not* triggering initialization when being accessed= . > * > * This method is useful to bypass initialization when setting a property. > */ > public function skipInitializerForProperty(object $object, string $name, = string $class =3D null): void; > /** > * Sets a property *without* triggering initialization while skipping hook= s if any. > */ > public function setRawPropertyValue(object $object, string $name, mixed $= value, string $class =3D null): void; > } For virtual proxies, it would be nice if the instance returned didn't have to be the same type or child type. For example, in Durable PHP, I allow accessing remote entities via a Spying Proxy: $ctx->signal($id, fn(MyEntity $obj) =3D> $obj->doSomething($x)); In this example, ->signal() generates/loads the proxy which implements MyEntity with code that captures the value of $x to be forwarded to a remote instance. It then calls the passed closure and captures the method + arguments passed. Most of the complexity is generating the objects themselves to implement the methods. It would be much simpler to implement magic methods that can intercept the method calls and not worry about generating an entire class every time a dev wants to use this functionality. In my case, none of the complexity actually goes away since I still need to generate concrete types of the correct type. That being said, I don't exactly have millions of users so if I still need to manually create this, I will. I just thought I'd toss out the idea of not needing an object of the correct type, just one that can handle the expected behavior. Robert Landers Software Engineer Utrecht NL