Is a static class member not restored after session reload?

Is a static class member not restored after session reload?

am 19.01.2008 20:40:28 von Gert Kok

I'd like to use 3 types of objects, which have a kind of
availability-check as a static object in their parent class.

After page reload the initialised member is NULL


Is this a PHP 5.2.5 feature or am I missing something?

------------------------------------------------
First page in a session:
------------------------------------------------
session_start();

class Checker {

function check () {
echo 'OK';
}

}
class Common {

protected static $checker;

}
class Special extends Common {

static function setChecker( ) {
parent::$checker = new Checker();
}

function show() {
echo parent::$checker->check(); <-- error !
}
}

Special::setChecker ( );

$_SESSION['b'] = new Special();

$_SESSION['b']->show();


OK
------------------------------------------------
second page in same session:
------------------------------------------------
(after start of session with class definitions)


$_SESSION['b']->show();

Fatal error: Call to a member function check() on a non-object

on the indicated line

Re: Is a static class member not restored after session reload?

am 20.01.2008 10:45:01 von Toby A Inkster

Gert Kok wrote:

> $_SESSION['b'] = new Special();

You are storing an instance of the Special class into the session.
However, Common::$checker is a static variable, and is not part of the
object you are storing, so will not be stored.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 20 days, 20:56.]

Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/