|
 Ben Simpson - 2014-01-16 14:30:37
Found an error on using this.
Works correctly but seems to change the variable after first instance.
For example:
if(!isset($page)) $page = 0;
if($page < -1) $page = -1;
var_dump($page);
gives:
Notice: Object of class GlobalLogger could not be converted to int
object(GlobalLogger)#3 (2) {
["value":protected]=>
string(1) "0"
["varname":protected]=>
string(4) "page"
}
 Matthew Daniel - 2014-01-16 15:09:00 - In reply to message 1 from Ben Simpson
Great, thanks for the heads up.
It appears to work correctly for me in the case where I add &page=1 to the get string i get 1 as expected during a var_dump. I do also get the notice that you posted. I have a work around for it so long as your site doesn't use a custom error handler or so long as you initialize after your custom error handler is set.
 Ben Simpson - 2014-01-16 15:13:19 - In reply to message 2 from Matthew Daniel
Hi, thanks for the quick reply! Could I get the workaround please?
 Matthew Daniel - 2014-01-16 15:18:26 - In reply to message 3 from Ben Simpson
I changed the file and uploaded it. If it isn't visible through phpclasses yet here is the change i added to the end of the initialize function.
set_error_handler(function ($errno, $errstr) {
// php can handle using class directly as an int but throws a notice
// this will prevent that from being reported
if ($errno == 8 && stripos($errstr, 'Object of class globalLogger could not be converted') !== false) {
return true;
}
return false;
}, E_NOTICE);
Let me know if he works out for you.
 Ben Simpson - 2014-01-17 12:21:39 - In reply to message 4 from Matthew Daniel
Hi,
Thanks for that.
The additional code hides the error notice but the underlying problem is still there.
I've tried it on a new blank project to make sure it's not my code causing issues and it still happens so possibly a difference in our hosting setup (I'm on Apache, PHP 5.3 with reg globals on).
To clarify, with querystring ?ben=hello with your code in place, var_dump of $ben shows:
object(globalLogger)#2 (2) {
["value":protected]=>
string(5) "hello"
["varname":protected]=>
string(3) "ben"
}
which means when I now do:
if($ben === "hello")
it no longer proves true when using your code.
Thanks
Ben
 Matthew Daniel - 2014-01-17 12:30:37 - In reply to message 5 from Ben Simpson
Hi,
This code will forever have the limitation of not being able to be strictly compared with the triple equals. The triple equals will compare value along with type which the registered global is definitely not a string.
Strict comparison will be an impossible limitation to work around unfortunately for this class since this class relies on the class magic method toString to log where these register globals are used in the code. For most cases (because register globals comes from inherently string/integer based data input) the double equals usually sufficed for comparison so if your code extensively uses strict comparison on registered global then you may be out of luck using this class.
 Ben Simpson - 2014-01-17 14:17:51 - In reply to message 6 from Matthew Daniel
Hello,
Completely understand, thought that might be the case, thanks anyway for all your help.
The code is still coming in useful for helping to identify the global regs being used, just means we can't log it on the live site.
Thanks again
Ben
|