php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80123 Cannot redeclare does not provide include reference
Submitted: 2020-09-19 22:02 UTC Modified: 2021-08-19 21:12 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: jab_creations at yahoo dot com Assigned: cmb (profile)
Status: Wont fix Package: Unknown/Other Function
PHP Version: 7.4.10 OS: *nix/Win
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jab_creations at yahoo dot com
New email:
PHP Version: OS:

 

 [2020-09-19 22:02 UTC] jab_creations at yahoo dot com
Description:
------------
When I have to debug an error like this:

Fatal error: Cannot redeclare session() (previously declared in D:\web\sessions.php:2)

...it does not tell me what file included the file with the session function. That forces me to do pointlessly convoluted debug.

I've tried doing back tracing however the error is reported and the process shuts down so I don't get the second back trace.

Test script:
---------------
An overly simplified version:
<?php
include('file1.php');//includes session.php.
include('file2.php');//includes session.php; error spawns, no second back trace.
?>

Expected result:
----------------
A much more useful error message would look something like:

Fatal error: Cannot redeclare session() (previously declared in D:\web\sessions.php:2, file included by file1.php, file included by file2.php).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-20 21:23 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2020-09-20 21:23 UTC] cmb@php.net
Use include_once instead, and don't get an error in the first
place?

Anyhow, I don't think this qualifies as a bug, but is more like a
feature request.
 [2021-08-19 21:12 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-08-19 21:12 UTC] cmb@php.net
This case doesn't appear common enough that it warrants to
maintain the include chain for each and every OP array.

> Use include_once instead, and don't get an error in the first
> place?

That.  Or maybe better require_once.

If you still want to see this, please pursue the RFC process[1].

[1] <https://wiki.php.net/rfc/howto>
 [2021-10-11 10:22 UTC] chanrith dot tang at allweb dot com dot kh
I have scanned my entire code and use require_once but the error still happens in my current and future versions. The error message is not helpful to find the source of the error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC