Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124187 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 71D6E1A009C for ; Wed, 3 Jul 2024 09:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720000594; bh=lQxjzKeRYdt6UGTeH277zXj6LJoSxBsijgM49rVx9zc=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=MVc+iKxeaOMUYJDQa44H3+sAtDTLSpNd/qiTvfrcJIgn+HaN3twiPjHMOy4AACcvw ZLNG30torItSEvG8z5VOQU6SspiR1oXq5Js14hnU1Ig6cXSzQKM1ogRdaaWucrSrdj ACwvJO7K3SYSfcskeGGWXGKC91NEEqPDQJ2lQ1WkWKbMTF3fSsLzIxzexWyxbinT+O yAp/6wZwBbzZicjw0hecQqZXD9tMyrv6zhBL9ZkjpaiXPacms6VIpFvwD54x8DrZGJ VbWwivcVcJzJLwEqS8DpZzhFobmdCbGgtJ/26pS03Maak4TYLdZWz1KA+aV5UD+Lyp 4b/JykOVt9yWg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 48A58180003 for ; Wed, 3 Jul 2024 09:56:34 +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-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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, 3 Jul 2024 09:56:33 +0000 (UTC) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-57d046f4afdso1498660a12.1 for ; Wed, 03 Jul 2024 02:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720000511; x=1720605311; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=dTd0vtlWaIrYjeMmguMhZzPZ9fpYGynugnIwQ9eDLes=; b=imwep4fAnTBintPHeMwJ6D4n3krNYMzpHQxhXE51QSXbIMRrOMVeWyqMXfHdzOY3Ou CssFrze+9sKjXqwa9nGgp9JNXMiusx8iRL2rFfN56MOENOtsTG1yqIv+22eKsoOnCuGq yDEAa2/TS06/NYWfRXlHxkOdn81wHrzK3kLRsr16UQJk3pvcC33yRKPpVNFhDBOiPPnA GvZwTB1oKJBw99POS5PPklxzjaRfyJTkbWJG696HNeDD/lReH77W9g+uTJu/4YIEFzvV QQSLnXt7l7AFDHNA9hbO90DQMNZ2SwpUYL5o2914MhYni9vl8bPrSRBRM59fVYR+NbWb Yxww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720000511; x=1720605311; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dTd0vtlWaIrYjeMmguMhZzPZ9fpYGynugnIwQ9eDLes=; b=XkfkN5ef70ExAJi8NtlFV8J4FnXqKLFT9NResV5LmQQbFDaJeuF5qKKiRoMg0tSepg fyQ4eOEGJkYjEh0FEi/c9x7SrjuyYX9nURgMi9zSkCAzraYRtYe9FOMrf/GuZkO0y4f9 ljvJpVSK0VD4JPtfjD+TghHvkssimpBcONLSLczYZoBVCA9sBfuFl1c5LD2S/ZDZM8lk xqVWQyoNWINiXa2xFK94OJ3vnAeXZJR62nMzl41pW1v3HpLgWUvYRyTdl6C0iJ+WMgsh MMIzB6Ul+nOf2Xcnn4MDDK1raZDbUceGl5E6bakY9a749IC8Zhungn0A6s1D9X+GHXNg PDgg== X-Gm-Message-State: AOJu0Ywczox/+7X5fhXiShXVDZHCl1qE9wXITEjnIrTY0k+A/zHddMH+ 890kH/R42BObdnabD7bHDqlHiBbrW6nTZGNuOn0uKYc+oSB7cEpW/S0o/A== X-Google-Smtp-Source: AGHT+IEDLjFMldA9oS+p7ZV2QVJSrg8jJ/x3SNNmWG5pJ3EfVVz3qiTt8IhDuG698HjihDDD7eLHOQ== X-Received: by 2002:a05:6402:84b:b0:57c:5f77:1136 with SMTP id 4fb4d7f45d1cf-5879f69b7bemr9665637a12.24.1720000510640; Wed, 03 Jul 2024 02:55:10 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58615038a86sm6798089a12.95.2024.07.03.02.55.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 02:55:09 -0700 (PDT) Message-ID: <8A3C2FDA-60DF-45A1-BA9D-11B6FB6F755C@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_09A7916A-1638-4A30-89F5-51D67FB372C1" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: [PHP-DEV] [RFC] Property Hook improvements Date: Wed, 3 Jul 2024 11:54:58 +0200 In-Reply-To: Cc: php internals To: Larry Garfield References: X-Mailer: Apple Mail (2.3774.600.62) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_09A7916A-1638-4A30-89F5-51D67FB372C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 1 juil. 2024 =C3=A0 19:02, Larry Garfield = a =C3=A9crit : >=20 > Hi folks. As Ilija's been polishing off hooks to get the PR merged, = we've run into two small revisions that should make life better for all = involved. One is a performance improvement that requires a very slight = error handling behavior change, and the other is enabling readonly in = selected (but probably all of the relevant) circumstances. >=20 > I'd say we expect these to be uncontroversial, but this is PHP. :-) = So I will instead just note that it's a short RFC and open the = discussion accordingly. >=20 > https://wiki.php.net/rfc/hook_improvements >=20 > --=20 > Larry Garfield > larry@garfieldtech.com Hi, 1. Removing the guard against recursion is sensible to me, as the sort = of bug it is supposed to prevent is not specific to property accessors. = IMO, a better solution to the issue is to implement a global upper limit = on the call stack size. Currently, I am able to generate a call stack of = more than 10 millions items before an OOM error occurs; PHP should have = thrown a stack overflow error long before that. But this is entirely = orthogonal to property hooks. 2. As for readonly, I think that the invariant it is supposed to provide = should be enforced as strictly as possible. It means that `readonly` is = only acceptable if there is no `get` hook. The primary reason I would want readonly with `get` hook, is lazy = initialisation, and I think that there is better design than to trust = the user for not implementing bugs. For that use case, I think it is = preferable to implement dedicated hook for lazy initialisation, = orthogonal to the readonly feature. Here is what I would suggest (in a = separate RFC, of course): * An additional hook, called `init`, may be added to backed properties. = When attempting to read the value of the backing store, if it is = uninitialised, then the `init` hook is triggered, which is supposed to = initialise it. In general, a hooked property can be marked as `readonly` when it is = backed and has no `get` hook. In particular, it can have an `init` hook, = which is all we need in order to have a lazy readonly property that is = robust against bugs by construction. =E2=80=94Claude --Apple-Mail=_09A7916A-1638-4A30-89F5-51D67FB372C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 1 juil. 2024 =C3=A0 19:02, Larry Garfield = <larry@garfieldtech.com> a =C3=A9crit :

Hi folks.  As Ilija's = been polishing off hooks to get the PR merged, we've run into two small = revisions that should make life better for all involved.  One is a = performance improvement that requires a very slight error handling = behavior change, and the other is enabling readonly in selected (but = probably all of the relevant) circumstances.

I'd say we expect = these to be uncontroversial, but this is PHP. :-)  So I will = instead just note that it's a short RFC and open the discussion = accordingly.

https://wiki.php.net/rfc/hook_improvements

-- =
 Larry Garfield
=  larry@garfieldtech.com

Hi= ,

1. Removing the guard against recursion = is sensible to me, as the sort of bug it is supposed to prevent is not = specific to property accessors. IMO, a better solution to the issue is = to implement a global upper limit on the call stack size. Currently, I = am able to generate a call stack of more than 10 millions items before = an OOM error occurs; PHP should have thrown a stack overflow error long = before that. But this is entirely orthogonal to property = hooks.

2. As for readonly, I think that the = invariant it is supposed to provide should be enforced as strictly as = possible. It means that `readonly` is only acceptable if there is no = `get` hook.

The primary reason I would want = readonly with `get` hook, is lazy initialisation, and I think that there = is better design than to trust the user for not implementing bugs. For = that use case, I think it is preferable to implement dedicated hook for = lazy initialisation, orthogonal to the readonly feature. Here is what I = would suggest (in a separate RFC, of course):

* = An additional hook, called `init`, may be added to backed properties. = When attempting to read the value of the backing store, if it is = uninitialised, then the `init` hook is triggered, which is supposed to = initialise it.

In general, a hooked property = can be marked as `readonly` when it is backed and has no `get` hook. In = particular, it can have an `init` hook, which is all we need in order to = have a lazy readonly property that is robust against bugs by = construction.

=E2=80=94Claude


= --Apple-Mail=_09A7916A-1638-4A30-89F5-51D67FB372C1--