fix: add false parameter to class_exists() guards to prevent autoloader collisions#6
Open
yanick29 wants to merge 1 commit into
Conversation
…er collisions
When class_exists('ClassName') is called without the second parameter false,
PHP triggers all registered autoloaders. This causes fatal errors when OES Core
is used alongside plugins that register their own autoloaders (e.g. WooCommerce
Action Scheduler, Jetpack Autoloader), as short class names like 'Config' or
'Container' are incorrectly matched and loaded from the wrong namespace.
This commit adds false to all 128 class_exists() guard calls across 87 files
in includes/. Runtime dispatch calls (27) that intentionally check for external
class availability are left unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Zusammenfassung (DE)
Dieser PR fügt den Parameter
falsezu allenclass_exists()-Guard-Aufrufen inincludes/hinzu, um Autoloader-Kollisionen mit Drittanbieter-Plugins zu verhindern.Problem
Wenn OES Core zusammen mit Plugins wie WooCommerce eingesetzt wird, die eigene PHP-Autoloader registrieren (Action Scheduler, Jetpack Autoloader), führen
class_exists('ClassName')-Aufrufe ohnefalsedazu, dass diese Autoloader unbeabsichtigt ausgelöst werden. Kurze, unqualifizierte Klassennamen wie'Config','Container'oder'Page'werden von externen Autoloadern fälschlicherweise als eigene Klassen erkannt und geladen. Das führt zu Fatal Errors.Beobachtete Fehler
Cannot declare class Action_Scheduler\Migration\Config— OES ruftclass_exists('Config')auf → der Action Scheduler Autoloader matchtConfigals Migration-Klasse → lädtmigration/Config.php→ beim zweiten Aufruf wird die Klasse doppelt deklariert → Fatal Error.Class "OES\Admin\Container" not found— OES ruftclass_exists('Container')auf → der Jetpack Autoloader lädt seine eigene\Container-Klasse → der Guard gibttruezurück → OES überspringt die eigene Klassendeklaration → späterer Code versuchtOES\Admin\Containerzu instanziieren → Fatal Error.Fix
class_exists('X')→class_exists('X', false)bei allen Guard-Aufrufen. Der Parameterfalseweist PHP an, nur im Speicher zu prüfen ob die Klasse existiert, ohne Autoloader auszulösen.IntlDateFormatter)Warum gegen
development?Dieser PR basiert auf dem
development-Branch (OES 3.0.0 Vorbereitung), da dort die aktive Entwicklung stattfindet und der Bug auch in der neuen Version noch vorhanden ist.Summary (EN)
This PR adds the
falseparameter to allclass_exists()guard calls inincludes/to prevent autoloader collisions with third-party plugins.Problem
When OES Core is used alongside plugins that register PHP autoloaders (e.g. WooCommerce with Action Scheduler and Jetpack Autoloader),
class_exists('ClassName')calls withoutfalsetrigger all registered autoloaders as a side effect. Short, unqualified class names like'Config','Container', or'Page'are incorrectly matched by external autoloaders, which then load classes from the wrong namespace, causing fatal errors.Errors observed
Cannot declare class Action_Scheduler\Migration\Config, because the name is already in use— OES callsclass_exists('Config')→ Action Scheduler autoloader matchesConfigas a migration class → loadsmigration/Config.php→ on a second call, PHP attempts to redeclare it → fatal error.Class "OES\Admin\Container" not found— OES callsclass_exists('Container')→ Jetpack Autoloader loads its own global\Containerclass → guard returnstrue→ OES skips declaringOES\Admin\Container→ later code tries to instantiate it → fatal error.Fix
Added
falseas the second argument to allclass_exists()guard calls:Scope
includes/Three guard patterns affected
if (!class_exists('X')) { class X ... }oes_include():if (!class_exists('Config')) oes_include(...)if (class_exists('Schema')) exit;Environment tested
After applying this fix, OES Core and WooCommerce run side by side without fatal errors.