I'm starting to program with object orientation in PHP. I came across the following problem: I have a Usuario
class and I need to access the object as soon as I log in to the site, but when I try to access the object and the function of other pages, it gives an error.
How do I access the object on another page?
$Usuario->metodo();
we have the user class and soon down
<?php
include_once("Conexao.php");
class Usuario extends Conexao
{
private $id;
private $nome;
private $senha;
private $sessao;
function setSessao($sessao){
$this->sessao = $sessao;
}...
the manager page that I instantiate and the user class and login
<?php
$usuario = new Usuario();
$usuario->logar();
?>
the index class which I want to use the instantiated object on the manager page
<?php
echo "<h1>".$usuario->getNome()."</h1>";
?>
The error that appears is this: Notice: Undefined variable: user in
C:\xampp\htdocs\ConstrutoresFree\MyBiz\index.php on line 221
Fatal error: Uncaught Error: Call to a member function getNome() on null in C:\xampp\htdocs\ConstrutoresFree\MyBiz\index.php:221 Stack trace: #0 {main} thrown in C:\xampp\htdocs\ConstrutoresFree\MyBiz\index.php on line 221
(thanks for the tips)