Private variable being added to php automatically

Asked

Viewed 31 times

0

I will try to explain the problem, however, I have already said that I could not even find words to research what happened:

I have a file php user.

<?php

    class Usuario{

        private $grupoPermissao = array(
                'superAdmin' => array(
                    'rodrigo_segatto','tiago_silva'
                )
        );

        function __construct(){
            session_start();
        }

        public function getGrupoPermissao(){
            return $this->grupoPermissao;
        }

        public function verificaUsuario(){
            if (!$this->usuarioEstaLogado()){
                $flash = new Flash();
                $flash->setFlash('Você não deve fazer login antes de acessar a página!','alert-danger');
                header('Location:../../View/Sistema/login.php');
                die();
            }
        }

    }

The archive process-login.php, redirecting to the index:

$flash = new Flash();
$flash->setFlash('Você efetuou login com sucesso!', 'alert-success');
header("Location:../../View/Sistema/index.php");

And the index.php file, with the following code start:

<?php 
    require_once '../../AutoLoad.php'; 
    $usuario = new Usuario(); $usuario->verificaUsuario(); 
?>

In index, if I log in before giving New in User, and print SESSION, it will print:

Array
(
    (
        [usuario] => rodrigo_segatto
        [email] => rodrigo_segatto@...
        [nome] => RODRIGO SEGATTO
    )
)

Otherwise, if you print SESSION after giving New to the user, it will create an object inside with my private variable groupPermissao, as we see below:

Array
(
    [usuario] => Usuario Object
        (
            [grupoPermissao:Usuario:private] => Array
                (
                    [superAdmin] => Array
                        (
                            [0] => rodrigo_segatto
                            [1] => tiago_silva
                        )
                )

        )

    [email] => [email protected]
    [nome] => RODRIGO SEGATTO
)

The strangest that the same system works perfectly local, however, on the server linux occurs this.

  • Are both versions of php the same? The "register_globals" directive in php.ini is "off"?

  • On the server is "On" and local "Off". Will this then?

  • It can be, disable to test. In newer versions of PHP is already disabled, which version is disabled and which of the server?

  • So this must be it, and I discovered that this mess was caused when the class name is the same stored in Sesssion. EX: class Usuario{ == $_SESSION['user'] . So I changed the name of the variables that go to the session and it worked.

  • Good that it worked. But to avoid the risk of creating a variable with the same name and override is nice to disable. Abs

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.