Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123885 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 DA1E21A009C for ; Wed, 26 Jun 2024 20:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719432474; bh=L1dKIxVfS0sWQ/Mje8GhevaCTu70AEJshnQNqYDHCYg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Z/m+eon23AUlyRpOK6EF+X8AsImw7LAptMTmIR3WZscFivotOUDFDnH0S4LuamIDO B3linvUI3Vu1jtZ2k1FtVJp2h3nU0qPAxChynnz+ylhEnjI73FD30lmxF3L7OS4oj3 1c7nk4OqpgZo/1NSD+4wEKrDGeqkiNuTfYyiAJhjgjVd19tr9/XBLxje8hEJQVHecT AuJCIuy4OHLujn9FgaFs5Nd+Vp8IqP+nJ+SilKpVcixYMzCQZhOQdqpY25/hQNi4sK 00FM2xGdm5wMsp/Qw3zKm61jwyVJtA9oMavNTMCY77rxeKw015LPtT2+Rfw2aYzhVg GKrua9HyPopHQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AAFB31801D5 for ; Wed, 26 Jun 2024 20:07:53 +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-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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, 26 Jun 2024 20:07:53 +0000 (UTC) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2ec595d0acbso51855161fa.1 for ; Wed, 26 Jun 2024 13:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719432394; x=1720037194; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=L1dKIxVfS0sWQ/Mje8GhevaCTu70AEJshnQNqYDHCYg=; b=VI8IYPIVzLYZ6q7tLqKXjE3e7oOyRS8h92j249MBlBvHkUCSIMHsFwJzyGcgQKbQQ1 xt6jFzqWGWrsr24bzrT5MKbjXpg1IgEWzbjsiaIozaFVREW9zm+e4l0JhnZSyLuwECKt HMo31wGH5jey2Ar/NeiUnjiszpAj5pOhgjVKulQF1Uenz8i1WMdy1waiV2w/nWemgg7X Z90GiBEPcU7HR0aR8ZRe5GuxxCFKmyh8K7DLrMtUACp2wEsyv8xmAiPIb8d55pU290Dk ySMl9cc3Ek+qvdnYcZ9VHqSomLPxM3kpzTgH00m/CZ6D5SLiGT9I+ivbMMX+T/jRCoEP KNCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719432394; x=1720037194; h=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=L1dKIxVfS0sWQ/Mje8GhevaCTu70AEJshnQNqYDHCYg=; b=oSrLQSx2UZB8eWm/XIxvcH+EPvxRbDkuJGbB41CZiqyK5ePICwEfKbmBzEWRoVZVLG 5p1leadQ+gaYigPT6tdFbwY65j7ISYjkJ0tgOeOsTy9nev3xWUPRxrlR14p5HlL+ZhO+ UJuptXb3WiihBaztwjQYke3aWR7pNayN/yn2v/938FV5827+7sPXZuOpPEXP7WwXaQg5 +iXba7qBmrq7WiCXNgZAxzpt1QCP7LGXZ8V+gRWxlRN5gj2mCMdG1g2kMY0ws+l3lLEC DO4wptuscfjDficLeP/ClD4yWV+ghSFvO+aAri42Jj+05poebAPv+jnRNrm52lddQZ2v rLDg== X-Forwarded-Encrypted: i=1; AJvYcCVTslXCEEu/ygZ5YJeTxvSfcL8nTxfIxSU2MUXConby1aHlS0GPISKJMe1M2Sv1Uhr/JWm4zdXoCA+GP1yPyw3V/mOlH9zDkA== X-Gm-Message-State: AOJu0YxO6LDkP2/bLQX8pEN+e2FFR6wcjPPvDfTK8xOBsSuTl+aG/M3m i6qQ2n1Yt0HQd/xxGLFur76EeFESv7kSjVAlK1681fzw2NWxt80Oq66C/jCnJ9AjA3lNcgdJKFv P/z68gc2tcOYamNCyE10rW3H5cac= X-Google-Smtp-Source: AGHT+IFWwBImv45g8UDALdRDcNd4Q5Psht19F8n+Z9h4z/2E7vRvWrParjrgEqi7/m7iZKYZWfRkZB45St2x2buL/vM= X-Received: by 2002:a2e:854f:0:b0:2ec:49b5:50d5 with SMTP id 38308e7fff4ca-2ec5b357a00mr83028421fa.41.1719432393727; Wed, 26 Jun 2024 13:06: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, 26 Jun 2024 22:06:21 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: "Gina P. Banyard" Cc: Nicolas Grekas , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000000b28e3061bd08dea" From: arnaud.lb@gmail.com (Arnaud Le Blanc) --0000000000000b28e3061bd08dea Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Gina, On Tue, Jun 25, 2024 at 5:59=E2=80=AFPM Gina P. Banyard = wrote: > The fact that an initialize() method has a $skipInitializer parameter > doesn't make a lot of sense to me. > Because at a glance, I don't see how passing true to it, and not calling > the method is different? > Calling initialize() with $skipInitializer set to true has the same effect as calling skipLazyInitialization() on all properties that are still lazy on the object. This can be used to manually initialize a lazy object afterwards, as property accesses will not trigger initialization anymore. This also ensures that the initializer function can be decref'ed. This should probably be split into two distinct methods. > Agreed > Does get_mangled_object_vars() trigger initialization or not? > No. get_mangled_object_vars() and array cast are among the few cases that do not trigger initialization. They are listed in https://wiki.php.net/rfc/lazy-objects#initialization_triggers. > This should behave like an (array) cast (and should be favoured instead o= f > an array cast as it was introduced for that purpose). > Exactly > How does a lazy object look like when it has been dumped? > The output of var_dump() on a lazy object is the same as on an object whose all properties have been unset() (except those initialized with setRawValueWithoutLazyInitialization() or skipLazyInitialization()). For convenience we also prefix the output with either `lazy ghost` or `lazy proxy`. I've added a var_dump section in the RFC. > > The initializer must return null or no value > *Technically* all functions in PHP return a value, which by default is > null, so this is somewhat redundant. > Agreed. I believe that formulating this like that makes it clear that any of "return null;", "return;", or implicit return, will work. Also, would this throw a TypeError if a value other than null is returned? > Agreed. Currently we throw an Error, but I will change that to TypeError. Best Regards, Arnaud --0000000000000b28e3061bd08dea Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Gina,

On Tue, Jun 25, 2024 at 5:59=E2=80=AFPM Gi= na P. Banyard <internals@gpb.moe> wrote:
The fact that an initialize() method has a $skipIn= itializer parameter doesn't make a lot of sense to me.
Because at a = glance, I don't see how passing true to it, and not calling the method = is different?

Calling initialize() with= $skipInitializer set to true has the same effect as calling skipLazyInitia= lization() on all properties that are still lazy on the object. This can be= used to manually initialize a lazy object afterwards, as property accesses= will not trigger initialization anymore. This also ensures that the initia= lizer function can be decref'ed.

This should probably be split into two dis= tinct methods.

Agreed
=C2= =A0
Does get_mangled= _object_vars() trigger initialization or not?

No. get_mangled_object_vars() and array cast are among the few cases= that do not trigger initialization. They are listed in https://wiki.php.net= /rfc/lazy-objects#initialization_triggers.
=C2=A0
This should behave like an = (array) cast (and should be favoured instead of an array cast as it was int= roduced for that purpose).

Exactly
<= /div>
=C2=A0
How= does a lazy object look like when it has been dumped?

The output of var_dump() on a lazy object is the same as on= an object whose all properties have been unset() (except those initialized= with setRawValueWithoutLazyInitialization() or skipLazyInitialization()). = For convenience we also prefix the output with either `lazy ghost` or `lazy= proxy`.

I've added a var_dump section in the = RFC.
=C2=A0
> The initializer must return null or no value
*Technically* al= l functions in PHP return a value, which by default is null, so this is som= ewhat redundant.

Agreed. I believe that= formulating this like that makes it clear that any of "return null;&q= uot;, "return;", or implicit return, will work.

Also, would this throw= a TypeError if a value other than null is returned?
<= br>
Agreed. Currently we throw an Error, but I will change that t= o TypeError.
=C2=A0
Best Regards,
Arnaud<= br>
--0000000000000b28e3061bd08dea--