[php-src] Issue #24519: Class that uses a trait is not found when instantiated before its declaration

From: Date: Wed, 21 Oct 2026 23:59:11 +0000
Subject: [php-src] Issue #24519: Class that uses a trait is not found when instantiated before its declaration
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253070@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24519 Author: sybrew ### Description This is the same report as [bugs.php.net #75771](https://bugs.php.net/bug.php?id=75771), which is still open. The following code: ```php <?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 ```plain 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.

« previous php.bugs (#253070) next »