Skip to content

Improve the error message of duplicated class declaration #13950

Closed
@takaram

Description

@takaram

Description

  • Foo.php
    <?php
    class Foo {}
  • Foo2.php
    <?php
    class Foo {}
  • test.php
    <?php
    include 'Foo.php';
    include 'Foo2.php';

With these files, test.php gives this result:

PHP Fatal error:  Cannot declare class Foo, because the name is already in use in /path/to/Foo2.php on line 2

This error message includes nothing about Foo.php, which sometimes makes debugging hard.
It would be nice if the error message includes the file path and line number of previously declared class. Probably like this:

PHP Fatal error:  Cannot declare class Foo, because the name is already in use (declared in /path/to/Foo.php on line 2) in /path/to/Foo2.php on line 2

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