Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123588 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 7267E1A009C for ; Wed, 12 Jun 2024 15:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718204899; bh=66bT8NOqhr5LTrgwuzZ73piG2iIsCaCV5l6nvgPevTY=; h=From:Date:Subject:To:From; b=BwW5T+tXKOALhrKOveHT7Vr6eO2iIJgb38Kpa3o/bYNZ+UAG+YgC5TjyxIEo+TDbv PR5hE0tm0XdhS3aZc3+r7WBTudF+ASzEKU3pBMxVedu9TT6w5UsUr00Otoj94mAiYi lOZ3jySUHUd9GIwUc2fsPBm5nOSvHH1H9iV2IowcCx83aSNlHT2EqrvLciCW1PFNYD 4O6/T+AqmIB/42vBSa0TrlmQqbg5+hOubCd+/+QSbnkvkQHViVPgoX8HZr4AUZQboo u2TDIvVtFlBanbwlpzFtVSR2t6MveuqcupX+gDphCVRtVux06aKBx8RFIbhaczg+bw TdBl585x6ohlQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 466F118004B for ; Wed, 12 Jun 2024 15:08:19 +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-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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, 12 Jun 2024 15:08:18 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6b072522bd5so21629016d6.2 for ; Wed, 12 Jun 2024 08:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718204829; x=1718809629; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=7F5JxOJeVtf18R6wik2LfoNF9qX4sd/lrzLz5zUl+CI=; b=c0BZ57JYQaodrlFsTmy4EGcgcHGwlKwyS4Tzg5bhjr7Fl5PNvTXkcsBAtHk6MsYGYZ ugUo6Slt2Pz+XJhUM3A8GXTvR3oA3fcv/C95rmBpBZBNQULJWRHSKJveE6EkUD/gVGyA CInJ+4ob7gEe79f0wzCENJChPnhTdU2hBE4JOIvg3cqNjpnRYyp0b76KqCQ/yPOWwt8n kjR2jWSE2K7wWzZIGZwOPoJ0BXqKBbkOTfGQBq0Vxb4rarBhqvFXAgGRS4hTPoNSKW0e DIUqGmZwnOcL995l4CQ3w9WLyRali2Wq8CP59cSoOLjIw/ErNgBlKTGxFPftbZnmHfyz lZ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718204829; x=1718809629; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7F5JxOJeVtf18R6wik2LfoNF9qX4sd/lrzLz5zUl+CI=; b=VwR/mVETtEaYpwko6cspvGLbNbaJFEwKxyw4cHo2swOLutKmLRQyYEKS6t60UeonVC b67hYgfxiPn1oeR8ghdKyNpqby+8cmvWqiV5pByXjKinWwPuDtx1IS2JGQvhJ4Xt2of8 5DJd6vVdXiusxzJOzrPzhkAQWO90yQSXu3oUluOr+N8j9GkN/1Q6TDXZUuy/xrZhSZVt TjC0MR/0TYqJanjdBhk3gCOLpbUNlgsP/tzDPLJDlqBsvxWTLj9lxkvwvGpCI9/Ha+bQ m7qEF7W1szVcl6+ldnCIjR+z8c0jwpvc1gWzz1EcEkI7UV482/cvYZUY2Y/Uu9d556Wc Xy/g== X-Gm-Message-State: AOJu0YxhpI7ruZJnI9FTSdA/eAB63LAWdhvcrPSm98I4CoLlBnMOsJmu 1JRYr8gB/GT2k0C6mtqQXBLwPTfd2La7QpS0WHH279PaWUK/JosdIG+Q7hI5ODKh7VjxaXMEM3w d36ly76stgH0FAI2I7jo86mWCqzF/HvRgF4x1Vw== X-Google-Smtp-Source: AGHT+IEJewn9Wp+Jg18xd2SOGOAKgEz/yUddJP2BEcT+9kuNYAtZUaz8ZE8K/4ec7g54TB/VNgw2oSWRf3z23liPSYk= X-Received: by 2002:a05:6214:4893:b0:6b0:7f36:8aed with SMTP id 6a1803df08f44-6b1a6d4e193mr23864056d6.46.1718204828886; Wed, 12 Jun 2024 08:07:08 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Date: Wed, 12 Jun 2024 17:06:58 +0200 Message-ID: Subject: [PHP-DEV] Property hooks, and &get-only write behavior To: PHP internals Content-Type: text/plain; charset="UTF-8" From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi everyone While reviewing the property hooks patch, Bob found a discrepancy in the implementation and the specification. There is an unfortunate mistake in one of the examples that suggests specific by-reference behavior that we did not intend to support. Specifically, from https://wiki.php.net/rfc/property-hooks#references (you'll have to scroll down a bit): ```php class C { public string $a { &get { $b = $this->a; return $b; } } } $c = new C(); $c->a = 'beep'; // $c is unchanged. ``` This example implies that the assignment `$c->a = 'beep';` will invoke `&get` to write to the contents of the reference. However, this is not the case. Direct assignments will, in the absence of `set`, fall back to the builtin write operation for backed properties, or throw for virtual properties. Instead of `$c->a = 'beep';`, the example _should_ have said: ```php $ref = &$c->a; $ref = 'beep'; ``` Here, `$ref = &$c->a;` _will_ call `&get`. What the example intended to show is that the reference returned by `&get` is detached from `$c->a` itself. That said, I did give this idea some thought. I think it would not have been unreasonable to automatically call `&get` and assign to the returned reference when there is a `&get` hook but _no_ `set` hook. However, when trying to implement this, I encountered some technical issues that make this currently unfeasible. So, we'd like to move forward with the original semantics: If there is no `set` hook, then the assignment will trigger a builtin write for backed properties, or an error for virtual properties. If you wish to achieve the behavior described above (using `&get` to write to the property), you can implement `set` to perform the write to the reference yourself. I hope that these semantics are acceptable for everyone. Ilija