Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alexpott opened this issue Mar 3, 2025 · 3 comments · May be fixed by #17960
Open

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

alexpott opened this issue Mar 3, 2025 · 3 comments · May be fixed by #17960

Comments

@alexpott
Copy link

alexpott commented Mar 3, 2025

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

@alexpott
Copy link
Author

alexpott commented Mar 3, 2025

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.

@alexpott
Copy link
Author

alexpott commented Mar 3, 2025

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.

@iluuu1994
Copy link
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.

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 3, 2025
We were already handling NULL as a case, but seem to have forgotten to
pass the ZEND_FETCH_CLASS_EXCEPTION flag.

Fixes phpGH-17959
@iluuu1994 iluuu1994 linked a pull request Mar 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants