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

PHP 8.6: cached static closure keeps `static::` of the first called class

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

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

@iluuu1994 がすでに取り組んでいます。

2026年9月26日 から。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, php
領域
compilers

調査の方向性

Start by running the supplied PHP reproducer with and without opcache, then compare the behavior around the bisected commit f47cd216e9537301471d6af770998fe5fe5c784c. Inspect the ZEND_DECLARE_LAMBDA_FUNCTION path and cached static-closure behavior, then verify that B::name() and C::name() return their respective class names, including the reported inherited-method variants.

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

説明

Description

The following code:

<?php
class A {
    public static function name(): string {
        return (static fn () => static::class)();
    }
}
class B extends A {}
class C extends A {}

var_dump(B::name(), C::name());

Resulted in this output:

string(1) "B"
string(1) "B"

But I expected this output instead:

string(1) "B"
string(1) "C"

8.4 and 8.5 give the expected output. 8.6.0RC2 does not, with or without opcache.

Bisected to f47cd216e9537301471d6af770998fe5fe5c784c (#23203). Its parent 969a50d9957bf6806452ae3f3434c6a30369cc1f gives "B", "C". Still reproduces on PHP-8.6 7f5658403c5afa1dd929768b4f5a5cc06ddb8a24 and master 69ca307e1d482c7959b22d594852264ee179fe45.

Cc @iluuu1994

Written with LLM assistance, per CONTRIBUTING.md. The code, outputs and bisect above are measured.

It also happens in inherited instance methods, and with new static() and get_called_class(). A non-static closure is fine. We hit it in bensampo/laravel-enum, where the second enum class gets instances of the first.

Unverified guess: ZEND_DECLARE_LAMBDA_FUNCTION returns the cached closure without checking the called scope, and all subclasses share the slot in the declaring op_array.

PHP Version
PHP 8.6.0RC2 (cli) (built: Sep 24 2026 20:13:06) (NTS clang 15.0.0)
Copyright © The PHP Group and Contributors
Built by Laravel Herd
Zend Engine v4.6.0RC2, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0RC2, Copyright ©, by Zend by Perforce
Operating System

macOS 26.6.2 (arm64)

主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 9時間
マージ済み PR(30日)
122

環境構築

はじめの一歩

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

php/php-src のほかの issue

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

似ている issue

C の issue をもっと見る

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

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