I have no idea if it's safe to use or not, so I have to ask you.
Haha, I'm not able to explain how this code works in plain english, but I can explain in the following example:
I need to know if this code is (un)safe to use in my public PHP-scripts, as I think it's easier than always doing this:
Code:
class Requests {
private $type;
public function __construct($type='') {
$this->type = strtolower($type);
$this->createObject();
}
private function createObject() {
switch($this->type) {
case 'post':
$arr = $_POST;
break;
case 'get':
$arr = $_GET;
break;
default:
$arr = array_merge($_POST, $_GET);
}
foreach ($arr as $key => $value) {
$this->$key = $value;
}
}
}
Code:
$post = new Request('post'); //makes me use all $_POST-variables as an attribute of $post
/*
Say the variables stored in $_POST are the following:
key1 => value1
key2 => value2
key3 => value4
key4 => value3
*/
echo $post->key1; // prints "value1"
echo $post->key2; // prints "value2"
echo $post->key3; // prints "value4"
echo $post->key4; // prints "value3"
Code:
$var1 = $_POST['key1']; //so that $var1 = value1
Comment