Skip to content

Missing trait causes fatal error unlike a missing interface or parent class #17959

Closed

Description

@alexpott

Description

The following code:

<?php
class A {
    use MissingTrait;
}

Resulted in this output:

Fatal error: Trait "MissingTrait" not found in /in/QPqKX on line 3

Process exited with code 255.

But I expected this output instead:

Fatal error: Uncaught Error: Trait "MissingTrait" not found in /in/QPqKX on line 3
Stack trace:
#0 {main}
  thrown in /in/bSnmM on line 3

Process exited with code 255.

PHP Version

8.2.0 - 8.2.27, 8.3.0 - 8.3.17, 8.4.1 - 8.4.4

Operating System

No response

Activity

  1. alexpott commented on Mar 3, 2025

    @alexpott
    Author

    Compare with the behaviour for a missing class.

    <?php
    
    class A extends Missing {
        
    }
    

    produces:

    Fatal error: Uncaught Error: Class "Missing" not found in /in/bSnmM:3
    Stack trace:
    #0 {main}
      thrown in /in/bSnmM on line 3
    
    Process exited with code 255.
    
  2. alexpott commented on Mar 3, 2025

    @alexpott
    Author

    Or interface

    <?php
    
    class A implements MissingInterface {
        
    }
    

    produces:

    Fatal error: Uncaught Error: Interface "MissingInterface" not found in /in/UV6mc:3
    Stack trace:
    #0 {main}
      thrown in /in/UV6mc on line 3
    
    Process exited with code 255.
    
  3. iluuu1994 commented on Mar 3, 2025

    @iluuu1994
    Member

    I would call this a feature rather than a bug. Recovering from inheritance errors can lead to subtle issues. It should almost certainly be fine here since this error occurs before the interface one, but this should still land in master and not in active branches.

  4. added a commit that references this issue on Mar 3, 2025
    f71c1c4
  5. alexpott commented on Mar 5, 2025

    @alexpott
    Author

    @iluuu1994 thanks! Your fix looks great!

  6. iluuu1994 commented on Mar 12, 2025

    @iluuu1994
    Member

    Thanks for the report! Should be fixed in master.

  7. added a commit that references this issue on Mar 12, 2025
    8731c95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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