Do not check PHP property value

0

I would like to instantiate a connection in PHP and do not show the values as an example user and password, if you use print_r (new nomedaclasse) the values are shown even using the private modifier. Is it possible to omit information such as user and password values? Here's part of the code:

    private $host="localhost";
    private $user="root";
    private $password="";
    private $dbname="test";         

    private function setLogin($l, $s){  
        $conn = new PDO("mysql:host=$this->host;dbname=$this->dbname","$this->user", "$this->password");                            
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
        $conn = $conn->prepare("SELECT login, senha FROM usuario where login = :login and senha = :senha");
        $conn->bindParam(':login', $l, PDO::PARAM_STR);
        $conn->bindParam(':senha', $s, PDO::PARAM_STR);
        $conn->execute();
        $linha = $conn->fetch(PDO::FETCH_ASSOC);
        if($linha == ""){
            echo "false";  
        }else{                  
            session_start();
            echo $_SESSION["logado"] = md5(uniqid(rand(), true));
        }
    }
    
asked by anonymous 21.05.2017 / 02:07

1 answer

0

You can use get_object_vars that if called out of class, will only show the public properties.

<?php

class foo {
    private $a;
    public $b = 1;
    public $c;
    private $d;
    static $e;

    public function test() {
        var_dump(get_object_vars($this));
    }
}

$test = new foo;
var_dump(get_object_vars($test));

$test->test();

// array(2) {
//   ["b"]=>
//   int(1)
//   ["c"]=>
//   NULL
// }
//
// array(4) {
//   ["a"]=>
//   NULL
//   ["b"]=>
//   int(1)
//   ["c"]=>
//   NULL
//   ["d"]=>
//   NULL
// }
?>
    
21.05.2017 / 02:21