ext/spl: spl_autoload() builds include filename from case-preserved class name#22594
Open
jorgsowa wants to merge 3 commits into
Open
ext/spl: spl_autoload() builds include filename from case-preserved class name#22594jorgsowa wants to merge 3 commits into
jorgsowa wants to merge 3 commits into
Conversation
…lass name The default spl_autoload() implementation lowercased the class name before appending the file extension, so a class like MyClass would only autoload from myclass.php, never MyClass.php. This is fine on case-insensitive filesystems (macOS, Windows) but breaks autoloading of any non-lowercase-named class on case-sensitive filesystems (Linux) unless the file on disk happens to be lowercase. zend_hash_exists() against EG(class_table) still uses a lowercased copy of the name, since the class table itself remains keyed by lowercase name.
…g backslash zend_string_concat2() takes raw (char *, size_t) pairs, so the class name doesn't need to be materialized as its own zend_string just to skip a leading backslash before use. lc_name is now built directly via zend_string_alloc()+zend_str_tolower_copy() from the adjusted pointer/length instead.
…name EG(class_table) stores zend_class_entry* via the _ptr APIs, so the post-load check for whether the class got declared can look it up case-insensitively directly, without spl_autoload() having to build and hold a separate lowercased zend_string for the whole call.
TimWolla
requested changes
Jul 4, 2026
TimWolla
left a comment
Member
There was a problem hiding this comment.
This is documented (and thus intentional) behavior.
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.
The default
spl_autoload()implementation lowercased the class name before appending the file extension, so a class likeMyClasswould only autoload frommyclass.php, neverMyClass.php. This is fine on case-insensitive filesystems (macOS, Windows) but breaks autoloading of any non-lowercase-named class on case-sensitive filesystems (Linux) unless the file on disk happens to be lowercase.This change breaks backward compatibility of spl autoloading; I'm not sure where it should be fixed, master or PHP 8.4. Or maybe it should be deprecated first?