Re: Issue with the casting of a SESSION variable
- From: AndreH <ahaupt@xxxxxxxxx>
- Date: Wed, 29 Oct 2008 05:00:50 -0700 (PDT)
On Oct 29, 1:37 pm, AndreH <aha...@xxxxxxxxx> wrote:
On Oct 29, 1:08 pm, Suhas Dhoke <suhasdh...@xxxxxxxxx> wrote:
On Oct 29, 4:00 pm, AndreH <aha...@xxxxxxxxx> wrote:
Good day,
I have the a bit of an issue with retrieving an object from php's
session.
I set a session variable "user" from the class User as follows:
$user = new User();
// ... do some stuff to $user
$_SESSION['user'] = serialize($user);
And try to retrieve the variable again later:
$user=(User)unserialize($_SESSION['user']);
But the last statement throws this error:
Parse error: syntax error, unexpected T_STRING in ...
Google did not produce any useful solutions to this problem; Other
than syntax issues, but I'm 100% sure it is not an earlier syntax
issue. The problem lies in the casting of session object.
Any help would be appreciated.
Regards,
Andre
Hello Andre.
You are trying (type-casting) while retrieving the details from
session to the variable.
There is no such type "User".
and also no need to add that.
Try without "(User)".
Thanks for the reply.
I removed the "(User)" part as follows:
$user=unserialize($_SESSION['user']);
But get an exception when I call one of its functions:
if($user->getSuperUser()) // Do something...
Here is the exception:
Fatal error: Call to a member function getSuperUser()
It works if I go:
$user = new User();
if($user->getSuperUser()) // Do something...
Here's my User class:
class User
{
var $ID = 0;
/* Some more members ... */
var $SuperUser = false;
function setValues($ID, /* Some more members ... */
$SuperUser)
{
$this->ID = $ID;
/* Some more members ... */
$this->SuperUser = $SuperUser;
}
function getSuperUser()
{
return $this->SuperUser;
}
}
Ok found my problem.
Somehow the $_SESSION["user"] variable is set to the boolean value
"false", even though this assignment is never made. So my program
tries to access the SuperUser method, which obviously doesn't exist
for a boolean.
Thanks for the help Suhas.
.
- References:
- Issue with the casting of a SESSION variable
- From: AndreH
- Re: Issue with the casting of a SESSION variable
- From: Suhas Dhoke
- Re: Issue with the casting of a SESSION variable
- From: AndreH
- Issue with the casting of a SESSION variable
- Prev by Date: Re: Issue with the casting of a SESSION variable
- Next by Date: Re: _POST is empty if a lot is entered into textarea in form
- Previous by thread: Re: Issue with the casting of a SESSION variable
- Next by thread: Re: Issue with the casting of a SESSION variable
- Index(es):
Relevant Pages
|