Skip to content

class_exists throws on missing extends/implements and fatal on missing trait #5236

@kkmuffme

Description

@kkmuffme

Affected page

https://www.php.net/manual/en/function.class-exists.php

Issue description

class_exists will throw if a class is autoloaded (= 2nd arg is true = default!), but any extends/implements of that class do not exist and cannot be autoloaded

Steps to reproduce

spl_autoload_register( function ( $class_name ) { 
    if ( $class_name === 'Foo' ) {
        require __DIR__ . '/foo.php';
    }
} );
class_exists( Foo::class );

foo.php

class Foo extends Bar {}

Suggested fix

Mention that it can throw an exception if the any of the classes that class extends/implements fails

Mention that it will result in a fatal E_ERROR if any of the "trait use" of the class do not exist (php/php-src#21106)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDocumentation contains incorrect information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions