Re: PHP 4.0 Bug #4285: Unexpected warning using an object in a session
| From: | Sascha Schumann | Date: | Mon, 01 May 2000 03:18:29 +0000 |
| Subject: | Re: PHP 4.0 Bug #4285: Unexpected warning using an object in a session | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-18317@lists.php.net to get a copy of this message | ||
On Mon, May 01, 2000 at 02:13:58AM -0000, yzhang@sfu.ca wrote:
> From: yzhang@sfu.ca
> Operating system: Linux (Redhat 6.0)
> PHP version: 4.0 Release Candidate 1
> PHP Bug Type: Session related
> Bug description: Unexpected warning using an object in a session
>
> An unexpected warning comes back when I use an object in a session variable:
>
> The code is this:
>
> <?
> error_reporting(15);
> session_start();
> session_register("SESSION");
>
> if (! isset($SESSION)) {
> class object {};
> $SESSION = new object;
> $SESSION->i = 5;
> } else {
> echo "My value is: $SESSION->i";
> }
> ?>
>
> Run it twice (first time to register the session, the second time to use it) and you will see
> this:
>
> Warning: Unserializing non-existant class: stdClass! No methods will be available! in
> /home/httpd/htdocs/test.php on line 3
> My value is: 5
>
> Not sure why this is a warning, what is stdClass? I find no mention of it in the manual.
The class definition must be available to the session engine.
Otherwise it won't be able to deserialize an object properly.
In this case, you need to move the class .. line before
session_start().
- Sascha