|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45963 Undefined variable should cause an error
Submitted: 2008-09-01 12:04 UTC Modified: 2016-01-24 04:22 UTC
Avg. Score:1.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: andyincolorado at gmx dot net Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 6CVS-2008-09-01 (CVS) OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: andyincolorado at gmx dot net
New email:
PHP Version: OS:


 [2008-09-01 12:04 UTC] andyincolorado at gmx dot net
In all PHP version I've tested so far, using an undefined variable (see code below) will cause a notice to be thrown. However, it would be better to throw an error, since using an undefined variable can cause unpredictable results or (as in my case) data loss. Same would go to the "undefined index" notice for arrays.
This could either be done by using an option, allowing users to turn it off or without an option, since PHP6 changes so many things that developers will have to adapt their scripts.

Reproduce code:
// Note that $bar isn't defined anywhere in the script
$foo = $bar + 5;

Expected result:
An error message that causes the script to cease running.

Actual result:
A notice ("Undefined variable $foo...") is thrown.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-15 14:38 UTC]
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2016-01-15 14:38 UTC]
"This could either be done by using an option"

If you set an error handler that throws an exception for all warnings, you will have the behaviour that you want.
 [2016-01-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 12:01:29 2024 UTC