Well, my question is more about how to reference and "get" the contents of a variable in a PHP Class. See excerpts from the code below, where I put wrong data for the connection, on purpose, to cause an exception to the PDO, and thus store the error msg in the msgErro variable. Hi, I'm using XDebug to do this, but I'm not sure how to do this, but I'm not sure how to do this. when debugging progresses, and returns to PHP's register, which looks at the debugger, this shows the local variables, in this case the object that took the properties of the class, but the value of the property (variable) $ u- > msgErro is empty (emptied)! and this is what I can not understand how it is empty, if a line before, in the variables of the file Usuarios.php, where the class is, was content.
file register.php . .
$u->conectar("xxxx","xxxx","xxx","");
if ($u->msgErro == "")
file usuarios.php // that contains the class
Class Usuario
{
private $pdo;
public $msgErro; //tudo ok
public function conectar($nome, $host, $usuario, $senha){
global $pdo;
try
{
$pdo = new PDO("mysql:dbname=".$nome.";host=".$host,$usuario,$senha);
}
catch (PDOException $e)
{
$msgErro = $e->getmessage();
}
}
}
When I test the variable $ msgErro in the file register, through the object $ u = new User;
if ($u->msgErro == "")
{
echo "esta mensagem ´é se msgErro está vazia!";
That is, in this test, there should be a negative of if, because there was an error in the connection, the error was placed in the variable $ msgErro there in the file usuarios.php, however, in the test of the file cadastrar.php, the variable is empty, so go straight through if. Any tips? grateful.