php / php/php-src

Assertion failure when freeing rvalue of ASSIGN_OBJ with typed refs and __toString()

Aperta
#20,316 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@arnaud-lb ci sta già lavorando.

Dal 28/10/2025.

Bug Status: Needs Triage
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

Description

The following code:

<?php

class C {
    public string $a = '';
    public $b;
    function __toString() {
        global $c; // turns rvalue into a ref
        return '';
    }
}

$c = new C;
$c->b = &$c->a;
$c->b = $c;

Resulted in this output:

zend_execute.c:4093: i_zval_ptr_dtor_noref: Assertion `zval_get_type(&(*(zval_ptr))) != 10' failed.

Root cause is that we call zend_assign_to_variable_ex() / zend_assign_to_typed_ref_ex() with value_type=IS_TMP_VAR, when value may be a CV slot here: https://github.com/php/php-src/blob/02c67b47f728f915e6015c2fd52c6e1f7a27b172/Zend/zend_object_handlers.c#L875-L876

Therefore the slot may have been modified when reaching this call: https://github.com/php/php-src/blob/02c67b47f728f915e6015c2fd52c6e1f7a27b172/Zend/zend_execute.c#L3665

With the code above, the assertion fails because orig_value is now a ref.

PHP Version
PHP 8.3
Operating System

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.