Req #45963 [Opn->Fbk]: Undefined variable should cause an error
| From: | danack@php.net | Date: | Fri, 15 Jan 2016 14:38:22 +0000 |
| Subject: | Req #45963 [Opn->Fbk]: Undefined variable should cause an error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198686@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=45963&edit=1
ID: 45963
Updated by: danack@php.net
Reported by: andyincolorado at gmx dot net
Summary: Undefined variable should cause an error
-Status: Open
+Status: Feedback
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Any
PHP Version: 6CVS-2008-09-01 (CVS)
Block user comment: N
Private report: N
New Comment:
"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.
Previous Comments:
------------------------------------------------------------------------
[2008-09-01 12:04:50] andyincolorado at gmx dot net
Description:
------------
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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45963&edit=1