Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123935 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 BC73F1A009C for ; Thu, 27 Jun 2024 10:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719484455; bh=qIRS38751gZipEYBUR3eb+uhpMZotXv70ssyLwPp5qs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UV9X6B9cVJYqNVO75Q4NPotnz0AP7BkcTWT53s0yi67WhO+cm7iKCxJu8KmrUzmZz nN79pjKyVSSK1jETRULEKuT7TELNPHo3L9+NG8WpcXUtidXMC16GlHdoXz10VjaUXm Me4USKIuHf9t9YyYiiwx73aVzJAGYffR7K318U9sSS9ETA0KzOep7yAfUDsIBBNCHQ JRGkrA/WFoMk35t+zOYiSsY7D96MG1bEImFgjHNXP1LOWEa8F0oS15no8Slcjtkzaa YlMT2wwcJTmxslDXwY3ViaVO1PIdBUqrbhNNprTYkkceA6q4tIUqfTPIU4JfOTuRHJ 6W7TGkwn3zuYA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D9BA180AAB for ; Thu, 27 Jun 2024 10:34: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-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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, 27 Jun 2024 10:34:13 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-6bce380eb96so5072766a12.0 for ; Thu, 27 Jun 2024 03:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719484375; x=1720089175; 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=qIRS38751gZipEYBUR3eb+uhpMZotXv70ssyLwPp5qs=; b=J73nRGetGwgSwb/rDSKcW0zIp8FgBrAvPTfX4MnSRTCBFPc55jGsfjYvTDzw5Xmb6X 3350iEhrmXuhiAolqN6t5dv23TyMm4MDPW+FyQmYjtzLtLo73rLAawrCWmD8ncw9dogh 1FIPYhfkai/lWQ4J6jNk0PjD15S3k8AmJJPhQUblEsO10lOnvy8Ap3MBHSEV1gkGJhIS /QMTbCmWc2Nv5C38zZuuVi5I1eAXkIRsOa8Jz7fsrYp/PAWTjqwHQnB0vxKBwEqeLG4V /zJAlkI42IngNfIjQskeBSm84RDHxb+BxZfhBuNOEKMT560iXu8JzaAZwDr8hDeVZTRk 9ADQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719484375; x=1720089175; 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=qIRS38751gZipEYBUR3eb+uhpMZotXv70ssyLwPp5qs=; b=RXMLXK9nVPiPsy/2qBtfJIcHnAYQRdoEt8R2NcA6GYKMbfdBr3cvqOBDEFKSpz09+p UwaXwbkOkWpB7m/HcjQaC5B1+ioUfqdUX+O1VexMYZ92zwV96swHJ/W4zCdfI5suwT/R VUyuShEgRZ7IZRJXtNTPuGSRH2jLxinYcCUTQMVnDMcWiMzG7e9sXscDm9c1iNqXOo1s 4jWIK3j9ydwaj9G8ejRArTiIgIYiZPkAN9stiSXIA6K6oUPXx12sJmi7y4uj4zWWbocY mvdETyLlF7yYSE4sHdAv65mosUF24+hAOwzMpXcZ1woZUSv6BLZ5/b0VxGWGGk1fVG9s MwLA== X-Forwarded-Encrypted: i=1; AJvYcCUWuM91R3YHlxdEtOn7FtDurXNAmnLAfbejSZK8V9dLic8GfkhYVZFX3QgC/KbkllttL2TPWmbSwIMslAabXFtyGzN2E4bWBA== X-Gm-Message-State: AOJu0YxDGccdZvGViCmYgIWjhcMXplVeSVfRzOJ+2uEvpTuXJsyzZJVf KVbLpqGtjVcxqqZi6YlRI2aHc+rAPrBtHQvgKscKx3WU25cCi8YM0jWR+SskXk5K58CnOdeeTbr UOfoQ7V5XVo9GC7OHg98PPJGnT+8= X-Google-Smtp-Source: AGHT+IFSjwt1g5u/i6CUsrYp/0/pkwpSkPk8XYAV/toDbihl5fIL+i/UaLzyzUSXURqAwEXvz4GJJJ5+1YYlw6TARbY= X-Received: by 2002:a05:6a20:6ab0:b0:1bd:4bb8:6509 with SMTP id adf61e73a8af0-1bd4bb868f0mr3923053637.55.1719484374433; Thu, 27 Jun 2024 03:32:54 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 27 Jun 2024 12:32:41 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: Arnaud Le Blanc Cc: Levi Morrison , Nicolas Grekas , PHP Internals List Content-Type: multipart/alternative; boundary="00000000000055ca5e061bdca753" From: ocramius@gmail.com (Marco Pivetta) --00000000000055ca5e061bdca753 Content-Type: text/plain; charset="UTF-8" Hey Arnaud, On Wed, 26 Jun 2024 at 21:06, Arnaud Le Blanc wrote: > The proposed implementation is adding very little complexity as it's not > adding any special case outside of object handlers (except in json_encode() > and serialize() because these functions trade abstractions for speed). > Furthermore all operations that may trigger an object initialization are > already effectful, due to magic methods or hooks (so we are not making pure > operations effectful). This means that we do not have to worry about lazy > objects or to be aware of them anywhere in the code base, outside of object > handlers. > > To give you an idea, it's implemented by hooking into the code path that > handles accesses to undefined properties. This code path may call __get or > __set methods if any, or trigger errors, and with this proposal, may > trigger the initialization. Userland implementations achieve this > functionality in a very similar way (with unset() and a generated sub-class > with magic methods), but they have considerably more edge cases to handle > due to being at a different abstraction level. > Assuming this won't pass a vote (I hope it does, but I want to be optimistic): is this something that could be implemented in an extension, or is it only feasible in core? Greets, Marco Pivetta https://mastodon.social/@ocramius https://ocramius.github.io/ --00000000000055ca5e061bdca753 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Arnaud,

On Wed, 26 Jun 2024 at 21:06, = Arnaud Le Blanc <arnaud.lb@gmail.= com> wrote:
The proposed imple= mentation is=20 adding very little complexity as it's not adding any special case=20 outside of object handlers (except in json_encode() and serialize()=20 because these functions trade abstractions for speed). Furthermore all=20 operations that may trigger an object initialization are already=20 effectful, due to magic methods or hooks (so we are not making pure=20 operations effectful). This means that we do not have to worry about=20 lazy objects or to be aware of them anywhere in the code base, outside=20 of object handlers.

To give you an idea,=20 it's implemented by hooking into the code path that handles accesses to= =20 undefined properties. This code path may call __get or __set methods if=20 any, or trigger errors, and with this proposal, may trigger the=20 initialization. Userland implementations achieve this functionality in a very similar way (with unset() and a generated sub-class with magic=20 methods), but they have considerably more edge cases to handle due to=20 being at a different abstraction level.

Assuming this won't pass a vote (I hope it does, b= ut I want to be optimistic): is this something that could be implemented in= an extension, or is it only feasible in core?

Greets,

<= /div>
--00000000000055ca5e061bdca753--