PHP 8.6: cached static closure keeps `static::` of the first called class
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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()andget_called_class(). A non-static closure is fine. We hit it inbensampo/laravel-enum, where the second enum class gets instances of the first.Unverified guess:
ZEND_DECLARE_LAMBDA_FUNCTIONreturns 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)
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.2k
- Ø Merge
- 2 T. 11 Std.
- Gemergte PRs (30 T.)
- 116
Entwicklungsumgebung
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php/php-src
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Flaky hrtime.phpt testOffenBug Category: Tests Status: Verified
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Bug SAPI: fpm Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
php/php-src#21740 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
johnsonjh/emu2-cpm86#68 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Zenmap CrashOffenZenmap
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
BasedHardware/omi#19306 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
fastfetch-cli/fastfetch#2619 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100