Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Class that uses a trait is not found when instantiated before its declaration

Aperta
#24,519 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, php
Ambito
compilers

Direzione di ricerca

Start by reproducing the example with the PHP CLI and compare behavior when class B uses a trait declared later. The issue names no source files or tests, so trace class and trait declaration handling in the Zend Engine and locate the relevant regression tests. Done when the first new B instance succeeds and calls traitfunc(), with a test covering the declaration order.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Status: Needs Triage
Description

This is the same report as bugs.php.net #75771, which is still open.

The following code:

<?php

new A; // good.
new B; // fatal error.

class A {
	function __construct() {
		echo "constructed A\n";
	}
}

class B {
	use T;

	function __construct() {
		echo "constructed B\n";
		$this->traitfunc();
	}
}

new B; // good.

trait T {
	function traitfunc() {
		echo "traitfunc called\n";
	}
}

Resulted in this output:

constructed A

Fatal error: Uncaught Error: Class "B" not found in /mnt/c/Users/sybre/AppData/Local/Temp/bug75771.php:3
Stack trace:
#0 {main}
  thrown in /mnt/c/Users/sybre/AppData/Local/Temp/bug75771.php on line 3

But I expected this output instead:

constructed A
constructed B
traitfunc called
PHP Version
PHP 8.5.12 (cli) (built: Oct 21 2026 22:48:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Operating System

Ubuntu 24.04 (WSL2). Also reproduced on PHP 8.4.4 on Windows.

Lingua principale
C
Stelle
40.7k
Fork
8.3k
Merge medio
2g 17h
PR unite (30g)
159

Preparare l'ambiente

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.

Altre issue di php/php-src

Tutte le issue di php/php-src

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.