fix(polyfill): bind the Compat surface eagerly at bootstrap#1
Merged
Conversation
Lazy aliasing left two holes the autoloader cannot close: 1. PHP never autoloads for parameter/return/instanceof checks. A Compat object passed to consumer code type-hinted with the PhpOffice name (e.g. `function f(Worksheet $ws)`) threw "TypeError: ... must be of type PhpOffice\...\Worksheet, EasyExcel\Compat\Worksheet\Worksheet given" unless something had happened to reference the class name first. 2. composer prepends its own autoloader, so a polyfill bootstrap loaded before vendor/autoload.php silently lost the PhpOffice\* namespace to a co-installed real phpoffice/phpspreadsheet. eagerAliasCompat() now class_aliases every implemented name at bootstrap (~60 classes, ~12 ms cold, one-time per process), enumerated by scanning the Compat tree (not .compat-surface.json, which tracks the full upstream surface including unimplemented classes). The prepended autoloader stays as the strict-mode tripwire for unimplemented classes. Already-defined names are skipped; EASY_EXCEL_EAGER=0 restores lazy-only aliasing. Found migrating a report pipeline whose SheetContext constructor type-hints Worksheet: creating the context fataled under strict mode. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Lazy aliasing left two holes the autoloader cannot close:
PHP never autoloads for parameter/return/instanceof checks. A Compat object passed to consumer code type-hinted with the PhpOffice name (e.g.
function f(Worksheet $ws)) threw "TypeError: ... must be of type PhpOffice...\Worksheet, EasyExcel\Compat\Worksheet\Worksheet given" unless something had happened to reference the class name first.composer prepends its own autoloader, so a polyfill bootstrap loaded before vendor/autoload.php silently lost the PhpOffice* namespace to a co-installed real phpoffice/phpspreadsheet.
eagerAliasCompat() now class_aliases every implemented name at bootstrap (~60 classes, ~12 ms cold, one-time per process), enumerated by scanning the Compat tree (not .compat-surface.json, which tracks the full upstream surface including unimplemented classes). The prepended autoloader stays as the strict-mode tripwire for unimplemented classes. Already-defined names are skipped; EASY_EXCEL_EAGER=0 restores lazy-only aliasing.
Found migrating a report pipeline whose SheetContext constructor type-hints Worksheet: creating the context fataled under strict mode.