Task #268
static $hasMQ to prevent multiple checking of get_magic_quotes_gpc()
| Status: | Closed | Start date: | 2010-04-15 | |
|---|---|---|---|---|
| Priority: | Low | Due date: | ||
| Assignee: | Alex Cartwright | % Done: | 100% |
|
| Category: | - | |||
| Target version: | 2.6.0 | |||
| PHP Version: |
Description
2.5.0
application/libraries/Input.php, line 90
protected function cleanInputData( $data ) {
static $hasMQ = null;
if ( is_array( $data ) ) {
foreach( $data as $key=>$val ) {
$data[ $this->cleanInputKey( $key ) ] = $this->cleanInputData( $val );
}
return $data;
} else if ( $hasMQ || function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
$data = stripslashes( $data );
$hasMQ = true;
} else {
$hasMQ = false;
}
static $hasMQ is supposed to prevent calling function_exists() and get_magic_quotes_gpc() multiple times.
If magic quotes is on, this prevention is effective because the condition $hasMQ returns true and the two other functions are not called. But if magic quotes is off, $hasMQ returns false (the second time) and the two functions are called.
Solution:
Change the elseif to:
else if ( $hasMQ || $hasMQ === null && function_exists ( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() )
which will result in calling the two functions only once. This fix might be applicable to other parts of the framework where a static is declared in order to save some load. I checked zula_clean() and its $transliteration array check works perfectly and just as intended.
If you want to test the effect, run this code:
(Change "return true" to "return false" to see the effect. Also, try removing "$mq === null AND" to see what's currently happening in Input.php)
function check_something() {
echo "I was called.. <br />";
return true;
}
class Test {
public function yeah() {
static $mq = null;
if($mq OR $mq === null AND function_exists('check_something') AND check_something()) {
echo "stripping slashes...<br />";
$mq = true;
} else {
$mq = false;
}
}
}
$test = new Test;
$test->yeah();
$test->yeah();
$test->yeah();
History
Updated by Alex Cartwright almost 2 years ago
- Status changed from New to Confirmed
- Assignee set to Alex Cartwright
- Priority changed from Undecided to Low
Updated by Alex Cartwright almost 2 years ago
- Tracker changed from Bug to Task
- Status changed from Confirmed to In progress
Updated by Alex Cartwright almost 2 years ago
- Status changed from In progress to Closed
- % Done changed from 0 to 100
Applied in changeset commit:"0d969f7ce52ccd9bee33e14afd876508f4ebb9c8".