PHP - "Strict Standards: Only variables should be passed by reference"

0

I have the next PHP class

<?php
class __lovie{
    private $ms;
    private static $i;
    private $llave;

    private function setKey(){
        $this->llave = '#$/($=';
    }

    public function __construct(){
        try {
            $g = parse_ini_file(__DIR__."/set/conf.ini.php");
            $this->ms = new PDO("mysql:host={$g['HST']};dbname={$g['DBN']}","{$g['USR']}","{$g['PWD']}",array(PDO::ATTR_CASE => PDO::CASE_NATURAL,PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
            __lovie::setKey();
        } catch (PDOException $e) {
            return $e->getMessage();
        }
    }

    private function crearIdentificacion(){
        $min = 1;
        $max = 0;
        switch(PHP_INT_SIZE) {
            case 4:
                $max = 2147483648;
                break;
            case 8:
                $max = 9223372036854775807;
                break;
            default:
                echo 'PHP_INT_SIZE is ' . PHP_INT_SIZE;
        }
        $diferencia   = bcadd(bcsub($min,$max),1);
        $rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8);
        return abs(bcadd($min, bcmul($diferencia, $rand_percent, 8), 0));
    }

    private function getLogin($e,$p){
        if (__lovie::ifExists($e,"emailPersona","personas")===true) {
            $querier = $this->ms->prepare("SELECT codePersona FROM personas WHERE emailPersona = :email");
            $querier->bindParam(':email',$e,PDO::PARAM_STR,70);
            $querier->execute();
            $resultado = $querier->fetchAll();
            if (count($resultado) == 1) {
                $tempVal = "";
                foreach ($resultado as $i) {
                    $tempVal = $i['codePersona'];
                }
                $realc = __lovie::desproteger($tempVal);
                if ($realc == $p) {
                    return true;
                }else{
                    $tempVal = null;
                    $realc = null;
                    return "LOG-ERR-CODE";
                }
            }else{
                return 'LOG-ERR-UNKNOWN1';
            }
        }else{
            return "LOG-ERR-EMAIL";
        }
    }

    private function ifExists($value,$columna,$tabla){
        $constructor = "SELECT {$columna} FROM {$tabla} WHERE {$columna} = :valor";
        $querier = $this->ms->prepare($constructor);
        $querier->execute(array(':valor' => $value));
        $resultado = $querier->fetchAll();
        //print_r($resultado);
        if (count($resultado) == 1) {
            return true;
        }else{
            return false;
        }
        $querier = null;
    }

    private function proteger($som){
        require_once __DIR__.'/../seguridad/class.php';
        $seguridad = new S(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
        $seguro = $seguridad->encrypt($som, $this->llave);
        return base64_encode($seguro);
    }

    private function desproteger($som){
        require_once __DIR__.'/../seguridad/class.php';
        $seguro = base64_decode($som);
        $seguridad = new S(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
        $inseguro = $seguridad->decrypt($seguro, $this->llave);
        return $inseguro;
    }

    public function registroPersona($nombre,$apellido,$email,$password){
        try {
            if(__lovie::ifExists($email,"emailPersona","personas") === true){
                return "REG-ERR1";
            }
            $id = __lovie::crearIdentificacion();
            $cont = 0;
            while (__lovie::ifExists($id,"idPersona","personas") === true) {
                $id = __lovie::crearIdentificacion();
                $cont++;
                if ($cont == 5000) {
                    return "REG-ERR-NOTREACH-ID";
                }
            }
            $code = __lovie::proteger($password);
            $querier = $this->ms->prepare("INSERT INTO personas(idPersona,nomPersona,apePersona,emailPersona,codePersona) VALUES (:id,:nom,:ape,:email,:code)");
            $querier->bindParam(":id",$id);
            $querier->bindParam(":nom",htmlentities($nombre,ENT_QUOTES,'utf-8'),PDO::PARAM_STR,100); //AQUI ES EL ERROR - WARNING.
            $querier->bindParam(":ape",htmlentities($apellido,ENT_QUOTES,'utf-8'),PDO::PARAM_STR,100);
            $querier->bindParam(":email",htmlentities($email,ENT_QUOTES,'utf-8'),PDO::PARAM_STR,70);
            $querier->bindParam(":code",$code);
            if($querier->execute()){
                return true;
            }else{
                return false;
            }

        } catch (PDOException $e) {
            return $e->getMessage();
        }
    }

    public function iniciarSesion($email,$password){
        try {
            $g = __lovie::getLogin($email,$password);
            return $g;
        } catch (PDOException $e) {
            return $e->getMessage();
        }
    }

}

$st = new __lovie();
$f = $st->registroPersona('Janny','Sophia','[email protected]','12345');
print_r($f);
/*$s = $st->iniciarSesion("[email protected]","12345");
print_r($s);*/
?>

My problem is that, when you run PersonRecord , an error of type Warning:

  

Strict Standards: Only variables should be passed by reference in /home/u845134273/public_html/lovie/aplication/modelo/class.php on line 135

I do not understand the reason for the error. What have I failed and how can I solve it?

It should be noted that since XAMPP works correctly without warnings, I have hosted the files in Hostinger now and that's where that message started to come from.

Weird, but bah! ...

In the configuration of the PHP version in Hostinger I changed from PHP 5.6 (The default) to 5.3 and the message does not appear ...

But in the same way, I need to work on PHP 5.6

Why do not you hide warning messages?

I do not opt for it, my plan is not to cover the mistakes. I need a totally clean website:)

    
asked by Máxima Alekz 21.03.2017 в 04:16
source

1 answer

1

Stores in a variable the htmlentities. And pass said variable to the bindParam

$nombreEntities = htmlentities($nombre, ENT_QUOTES, 'utf-8');
$querier->bindParam(":nom", $nombreEntities, PDO::PARAM_STR,100);

Do it in all cases that you use it.

    
answered by 21.03.2017 / 13:50
source