note 11358 added to Session handling functions

From: Date: Sat, 17 Feb 2001 22:56:31 +0000
Subject: note 11358 added to Session handling functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-11190@lists.php.net to get a copy of this message
// be careful when storing cross linked objects in sessions! // it took me quite a while to figure out! though it's clear // that it can't work. class a { $parent; function a(&$parent) { $this->parent = $parent; } function do_something() { echo $this->parent->id; } } class b { $id; $child; function b($id) { $this->id = $id; $this->child = new a($this); } } session_start(); if (!session_is_registered("my_object")) { session_register("my_object"); $my_object = new b("foo"); } $my_object->child->do_something(); // this will create serious problems // if called after the session was restored! // since php can't restore the reference to // the parent object. and php doesn't like // references to null objects ;-) http://www.php.net/manual/en/ref.session.php

« previous php.notes (#11190) next »