php / php/doc-en

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

Open
#5,236 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

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 (https://github.com/php/php-src/issues/21106)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the class_exists documentation at the affected PHP manual page and compare its current autoloading behavior description with the reproduction examples. Update the documentation to mention exceptions from missing parent classes or interfaces and fatal errors from missing traits, using the linked PHP issue for the trait behavior. Done means both failure modes are accurately documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.