Skip to content

Cannot redeclare previously declared ambiguity #23852

Description

@jabcreations

Description

From an error.log report:

[22-Sep-2026 18:51:21 UTC] PHP Fatal error: Cannot redeclare example() (previously declared in D:\wamp\errors.php:11) in D:\wamp\errors.php on line 11

This ambiguous error has wasted a lot of developer's precious time. It tells us where the function is declared but it fails to tell us where the file is included a second time. This results in developers opting to use include_once() instead of include() and tracking down errors in logic.

A proper fix applied to the same scenario should result in the following error report:

[22-Sep-2026 18:51:21 UTC] PHP Fatal error: Cannot redeclare example() from D:\wamp\test.php:427 (previously declared in D:\wamp\errors.php:11) in D:\wamp\errors.php on line 11

PHP Version

PHP 8.3.32

Operating System

No response

Activity

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