Error using an object in session

1

  

[Wed Sep 02 13:55:17 2015] [error] [client 192.168.1.105] PHP Fatal error: main () [function.main]: The script tried to execute a method or access to property of an incomplete object. Please ensure that the class definition "UserID" of the object you are attempting to operate on is loaded before unserialize () gets called or provide a __autoload () function to load the class definition in / opt / lampp /htdocs/renan/suc_validation.php on line 11, referer: link

My class

<?php

/* Declara o bloco de definições do usuário logado SUC */

if (!class_exists('UsuarioID')) {

class UsuarioID {

    public $COD_IDENT_USUAR = -9999;
    public $COD_IDENT_IGREJ = -9999;
    public $TXT_NOMEX_USUAR = 'Anônimo';

    function setCOD_IDENT_USUAR($p_COD_IDENT_USUAR) {
        $this->COD_IDENT_USUAR = $p_COD_IDENT_USUAR;
    }

    function getCOD_IDENT_USUAR() {
        return $this->COD_IDENT_USUAR;
    }

    function setCOD_IDENT_IGREJ($p_COD_IDENT_IGREJ) {
        $this->COD_IDENT_IGREJ = $p_COD_IDENT_IGREJ;
    }

    function getCOD_IDENT_IGREJ() {
        return $this->COD_IDENT_IGREJ;
    }

    function setTXT_NOMEX_USUAR($p_TXT_NOMEX_USUAR) {
        $this->TXT_NOMEX_USUAR = $p_TXT_NOMEX_USUAR;
    }

    function getTXT_NOMEX_USUAR() {
        return $this->TXT_NOMEX_USUAR;
    }

    function sair() {
        $this->COD_IDENT_USUAR = -9999;
        $this->COD_IDENT_IGREJ = -9999;
        $this->TXT_NOMEX_USUAR = "Anônimo";
    }

}

}
?>
  

I have tried to implement the __sleep method already tried to give serialize (); but in both cases they did not work, what else could it be?

    
asked by anonymous 02.09.2015 / 21:52

1 answer

1

The error happens because it does not include the class file in the document, the solution was very simple just add:

global $suc;
include 'suc.php'

In the page where I use the class in the session. It was not necessary to use serialize() and unserialize() , much less the __sleep method. The error was solved by adding a include 'suc.php' which is my class.

    
03.09.2015 / 14:31