Skip to content

ext/spl: spl_autoload() builds include filename from case-preserved class name#22594

Open
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:fix/spl-autoload-case-preserved-filename
Open

ext/spl: spl_autoload() builds include filename from case-preserved class name#22594
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:fix/spl-autoload-case-preserved-filename

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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.

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?

jorgsowa added 3 commits July 4, 2026 15:54
…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 TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented (and thus intentional) behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants