Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/05/2012, 15:16
Avatar de ONahuelO
ONahuelO
 
Fecha de Ingreso: junio-2009
Ubicación: Gualeguaychú, Argentina
Mensajes: 144
Antigüedad: 17 años, 3 meses
Puntos: 4
[Seguridad] Funcion para recibir datos

Hola, navegando por la web encontre esta funcion (joomla) para juntar valores, y queria preguntar si es segura para usarla en datos que son usados posteriormente en mi db.

Código PHP:
function getValue(&$array, $name, $default=null, $type='')
{
        
// Initialize variables
        
$result = null;
 
        if (isset (
$array[$name])) {
                
$result = $array[$name];
        }
 
        
// Handle the default case
        
if (is_null($result)) {
                
$result = $default;
        }
 
        
// Handle the type constraint
        
switch (strtoupper($type))
        {
                case 
'INT' :
                case 
'INTEGER' :
                        
// Only use the first integer value
                        
@ preg_match('/-?[0-9]+/', $result, $matches);
                        
$result = @ (int) $matches[0];
                        break;
 
                case 
'FLOAT' :
                case 
'DOUBLE' :
                        
// Only use the first floating point value
                        
@ preg_match('/-?[0-9]+(\.[0-9]+)?/', $result, $matches);
                        
$result = @ (float) $matches[0];
                        break;
 
                case 
'BOOL' :
                case 
'BOOLEAN' :
                        
$result = (bool) $result;
                        break;
 
                case 
'ARRAY' :
                        if (!
is_array($result)) {
                                
$result = array ($result);
                        }
                        break;
 
                case 
'STRING' :
                        
$result = (string) $result;
                        break;
 
                case 
'WORD' :
                        
$result = (string) preg_replace( '#\W#', '', $result );
                        break;
 
                case 
'NONE' :
                default :
                        
// No casting necessary
                        
break;
        }
        return 
$result;
}