opless / phpliteadmin

Automatically exported from code.google.com/p/phpliteadmin
0 stars 0 forks source link

$error variable undefine (notice) #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
the attached screenshot shows that the undefined $error variable is on line 
1458 but I think it is actually on line 1457.
when there is no error after a user action, the $error variable is not set so 
the check "if ($error)" throws a notice. (php version 5.3.3, with xdebug)
It is fixed by setting the variable to false before the switch statement 
(switch($_GET['action'])" on line 1166.
or in the if statement on the line of the error: if (isset($error) && $error)  

Original issue reported on code.google.com by sci...@gmail.com on 23 Apr 2011 at 12:12

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by daneirac...@gmail.com on 23 Apr 2011 at 6:53

GoogleCodeExporter commented 9 years ago
If you browse from svn version 1.8.3, the undefined $error variable is on line: 
1491 while on version 1.8.2 is on line: 1485.
And on the code i downloaded from here the 23 or 22 of April (which should be 
version 1.8.2) is on line: 1457.

You can't have:
if ($error) without $error not initialized in php;
In the big switch statement above the if ($error) line, (where you switch on 
user actions) if there is no error then the $error variable is never set to 
true or false.
so PHP throws an E_NOTICE.

I am attaching 2 screen-shots, 02 is a screen-shot of the code i downloaded 
from here, screen-shot 03 is a screen-shot of version 1.8.3 from browsing your 
svn, and also i am attaching the code i have download from here.

hope the above helps
cheers
_andrea

Original comment by sci...@gmail.com on 23 Apr 2011 at 8:50

Attachments:

GoogleCodeExporter commented 9 years ago
This should now be fixed. I changed the line to simply:

if(isset($error))

Original comment by daneirac...@gmail.com on 23 Apr 2011 at 10:43

GoogleCodeExporter commented 9 years ago
Hi,

sorry i don't mean to be pedantic but:
the reason for doing if (isset($error) && $error) rather then simply if 
(isset($error)), is that if someone decides to initialize the $error variable 
at the top of the block, then your if (isset($error)) will return true even if 
$error is false, so your fix, fixes a bug but introduces the possibility for 
another.
While with the double check you fix it and forget about it, unless the logic 
changes.

cheers
_andrea

Original comment by sci...@gmail.com on 23 Apr 2011 at 11:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Good catch. $error isn't being initialized until an error actually happens, so 
as of the current version, $error will never be false. That might change 
though, so I think your idea is the way to go. I just fixed it.

Original comment by daneirac...@gmail.com on 24 Apr 2011 at 1:01