Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#24,519 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, php
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
40.7k
フォーク
8.3k
平均マージ
2日 16時間
マージ済み PR(30日)
151

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。