Skip to content

Single backslash triggers autoloading with empty string #2379

@istepaniuk

Description

@istepaniuk

Description

The following code:

<?php

spl_autoload_register(function ($class_name) {
    var_dump($class_name);
});

class_exists('\\');

Resulted in this output:

string(0) ""

But I expected NO output instead.

This seems unexpected. Calling class_exists(''); does not trigger the autoload callback, but a single backslash in the class name does (as does invoking method_exists('\\', 'test'), etc.)

I might be wrong but I can't think of a reason why to invoke the callback in this case, in fact, composer fails because it assumes that $class_name is never empty.

PHP Version

8.2 (and others)

Operating System

Debian 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions