Skip to content

Error message of Class not found is incorrect when parent class is not defined or defined in other file #20814

@chopins

Description

@chopins

Description

  1. when parent class is not defined:
    The following code:
<?php
new A;
class A extends B {
}

Resulted in this output:

Fatal error: Uncaught Error: Class "A" not found

But I expected this output instead:

Fatal error: Uncaught Error: Class "A" parent Class "B" not found
  1. the parent class defined in other file:
    In test2.php define class B:
<?php
class B {}

In test.php extend class B:

<?php
include_once 'test2.php';
new A; //if after define Class A will correct
class A extends B{
}

Resulted in this output:

Fatal error: Uncaught Error: Class "A" not found

But I expected this no Error be throwed

  1. in same file, no error
class B {}
new A;
class A extends B {}

//other defined
new A;
class B {}
class A extends B {}

PHP Version

PHP 8.3 and 8.4 and 8.5.0-dev

Operating System

No response

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