Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123593 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 94F641A009C for ; Thu, 13 Jun 2024 08:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718267716; bh=oIqgRbzEJ816KnYEKQBk+TOyKeBmsmJ19csjGRf1KLo=; h=References:In-Reply-To:From:Date:Subject:To:From; b=MuRb8mrNtMlVeh4aqfGfNn7ZlCZHS3mKE0ZZ7XebkrycqxPwjKNtcR6MzQYrZ41j3 mn109otmBLrnkQPQElSQjftZWFKmV9Ex2mcAT1/WmKhxBblJEs9+Zkkk04FgTnRUVh 54P9FXhCRzoUSJYyuHRuTu3oZDFUhkezRjRZxOojpuGdnAjhQhZeU8CjJtXBnkCbZ5 sWkGZwzx2/L/JhdSyJ7yjmN7nJrBg+Sj/5QL3xhS1EFEZJ3gOR2K8nVqFEgV07wVS8 bcznfUbf6rCQ79Lxv9/ZzSC56/OLv6kmPl8q32fEo6obicRr4VXZbKJlCFiYST5lnB 1ZAgPs0aFwTbw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD54218004B for ; Thu, 13 Jun 2024 08:35:15 +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-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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, 13 Jun 2024 08:35:15 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6b06b78e716so4706466d6.3 for ; Thu, 13 Jun 2024 01:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718267645; x=1718872445; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oIqgRbzEJ816KnYEKQBk+TOyKeBmsmJ19csjGRf1KLo=; b=L3BLSkWNguJyNYVSKrFHnalNZCcRjWWMnBd9EfJRtmJHv5BPyaTlJHfnBUPiNF4l91 HIFXlb4s5pNCS33pmVVjXCEZlNi/Y+k6BRqj91AgnEPyuonCemB74Dw0wav6mBhn2YBv UvNhTA0A+FUIZtarpn4np+GQnBtn5RpsgI9nhCel7GUUJ7c196Tm21Dys7U5DzwLEEiX rwuKesQm1JM1jbTzEH6WhgXoRnEzdF8La04XsgzQyF02W19VD7iDVvkgLhAdeCvM/ALo TfnCISv9uzofFvpJSeuoIN2kSdhmV6lhJDFeJ8CHU34HLHCLEn5eK2lB8qQKH51eaeAb GAaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718267645; x=1718872445; h=content-transfer-encoding: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=oIqgRbzEJ816KnYEKQBk+TOyKeBmsmJ19csjGRf1KLo=; b=w9kPZiomzmnxfM1AwQUnv96goGX72JPu1wVGZxwQgCxftwd7wDi9WY98pKpotXRaeM akECftBGr+PlxXk6AerG4BlCY1vU/GeHUJwvsvaaQtKnQ7QkZF0yk64VMdorq9AhRjw+ XUvLOs6yU810G33hBwh5Ab/Qc8SntrZxPXioXxxh19woJEJ8RwNTxjHO5+9clEh8NJ2c 2rKbYsK9uYEre4YXncsAKtuiq+mkAWQO/CkMsdC6rrxfXGP6GaochjHaI5+qQA4orcEv 16xwkBQ23n2BqH01PGSeRdhuGLu9RE0fSqrdHc58QUNfAMc2At47Pe7rWbRM8WMGb5ce Y4pA== X-Gm-Message-State: AOJu0YzujaAC77zcKE4SpxOKR1K9o92sLHtJ4VZcQyfhtsqHHh3GYtov h+CkZ/lnWg1S23EJCT1/FAcvruNyAhHfX4WB+HkbwkSeQb30A1cJOYcLtYnjfxOmHj8ZWXkHE18 yIuk9ZBkXOIw0nx3Uhty5PnT83cAFXyD6fZc= X-Google-Smtp-Source: AGHT+IGZ1FDrIWQWwtdlX7r3Bh0/zDKQn3eknkxd8U2qhOO4ybYWBB/t/rl172fUYwwPXNBm9W021QfBL0h/MFnvHe8= X-Received: by 2002:a05:6214:2f85:b0:6b0:71ff:21a6 with SMTP id 6a1803df08f44-6b1a6a629dfmr44856776d6.39.1718267645030; Thu, 13 Jun 2024 01:34:05 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 13 Jun 2024 10:33:54 +0200 Message-ID: Subject: Re: [PHP-DEV] Property hooks, and &get-only write behavior To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Gina On Thu, Jun 13, 2024 at 3:24=E2=80=AFAM Gina P. Banyard = wrote: > > On Wednesday, 12 June 2024 at 16:06, Ilija Tovilo wrote: > > > Hi everyone > > > > [...] > > > > I hope that these semantics are acceptable for everyone. > > > > Ilija > > Hello Ilija, > > I might know what sort of technical issues you've been running into, as I= have some similar issues correctly handling references with my Container/O= ffset RFC implementation. > The way I'm handling this is by splitting the "get"/read handler/hook to = *just* be a by-value return, and for fetching creating a new "fetch" handle= r that is called in the respective situations. > Therefore, I am wondering if it wouldn't possibly make more sense to add = a "fetch" hook, and ban returning by-ref for the get hook. I don't know exactly what issue you encountered, but it sounds unrelated to mine. The issue was not related to the design of &get, but the way object handlers work for properties. In particular, get_property_ptr_ptr does not provide zval space for temporary values. There are three object handlers relevant: * get_property_ptr_ptr, which returns a direct pointer to the property zval. This is usually used for read+write operations such as ++, or when assigning by-ref, like =3D&. * read_property * write_property read_property and write_property are also used as fallbacks when get_property_ptr_ptr returns NULL. This is the case for hooks. Essentially, for hooks, we want to make sure the engine does not bypass the set hook by writing to the zval directly. Pure assignments aren't really an issue, I was able to implement them using write_property. When a value is assigned to a &get-only property, we call &get and assign the value to the resulting reference. However, for read+write operations, the flow works like this: * get_property_ptr_ptr returns NULL, indicating that a direct modification of the zval is not possible. * The engine calls read_property instead. * It modifies the resulting value. * It calls write_property with the new value. With this workflow, &get gets called twice, once for read_property and once for write_property, which is the unexpected part. I would expect &get only to be called once, and for this value to be modified in-place. To implement this properly, get_property_ptr_ptr should return the reference instead. However, the way get_property_ptr_ptr is built doesn't allow for this, because unlike read_property, it doesn't have a `zval *rv` parameter the caller must supply that the callee may use in the case of temporary values (such as &__get, or here, &get). So, rather than causing a big internal API change to add the `zend *rv` parameter (this API is very old), I opted to go with the original plan. I hope that helps. Ilija