Answer the question
In order to leave comments, you need to log in
Dynamic setting of object properties, will it eat up a lot of performance?
Essence in the following:
There is one method and one function. The method takes an array, escapes it, and returns. And the function takes an array and an object, after which it sets the properties of the received object to values from the passed array.
So, I pass the super global $_POST to the method, after which I pass a clean array to the function and get the object I need with the given properties. But I wonder if these not cunning manipulations will have an impact on performance, and if so, how much.
Method:
public static function arrayEscape(array $array, $deliteEmptyKeys=false){
if($deliteEmptyKeys){
foreach($array as $key => $value){
if(!empty($value)){
$clean[$key] = static::$db->escape($value);
}
}
}
else{
foreach($array as $key => $value){
$clean[$key] = static::$db->escape($value); /* Вызывается метод экранирования строк, хранящийся в статической переменной $db */
}
}
return $clean;
}
function arrayToObject($object, array $arr){
$prop=get_object_vars($object);
foreach($arr as $key=>$value){
if(array_key_exists($key,$prop)){
$object->$key = $arr[$key];
}
}
}
$clean = Db_querys::arrayEscape($_POST,true);
arrayToObject($object,$clean);
$object->prop1 = $db->escape($_POST['prop1']);
$object->prop2 = $db->escape($_POST['prop2']);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question