Assigning property value through readonly array results in "Cannot modify readonly property"
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia eseguendo il reproducer fornito su PHP 8.2.23 e 8.3.11 e confrontalo con l’accesso rifattorizzato tramite una variabile temporanea. Traccia la gestione delle proprietà readonly per l’espressione diretta $a->[0]->b nell’interprete PHP; il lavoro è completato quando l’assegnazione diretta aggiorna B::$b e stampa bar senza un errore fatale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The following code:
<?php
class A {
public function __construct(
public readonly array $a,
) {}
}
class B {
public function __construct(
public string $b,
) {
}
}
$a = new A([ new B('foo') ]);
$a->a[0]->b = 'bar';
echo $a->a[0]->b;
Resulted in this output:
PHP Fatal error: Uncaught Error: Cannot modify readonly property A::$a in /test.php:17
But I expected this output instead:
bar
If you try to change the property of an object that is inside a readonly array, based on syntax it thinks you're change the array itself and throws a Fatal, even though that property we're actually trying to change ($a->a[0]->b) is not readonly and can be changed. If the code to change the B::$b property is refactored like this the code works as expected:
$a = new A([ new B('foo') ]);
$b = $a->a[0];
$b->b = 'bar';
PHP Version
8.2.23, 8.3.11
Operating System
No response
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.2k
- Merge medio
- 2g 15h
- PR unite (30g)
- 103
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
Bug SAPI: cli_server Status: Verified
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Bug Status: Needs Triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Flaky hrtime.phpt test ApertaBug Category: Tests Status: Verified
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
api7/lua-resty-saml#63 ·
-
[Bounty proposal] fix(web): memory insights count an evening memory on the next day ($25 proposed) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
BasedHardware/omi#15320 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 commenti ·