note 86249 added to class.arrayobject

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
The code above will pretty much work as it is, though I have since added in some features.

Further notes: 
1. Be very aware of this bug until 5.3 becomes stable.
http://bugs.php.net/bug.php?id=41528

Basically, we wrote this collection to be a java-like object cache stored in session (instead of  hitting the soap server or a DB all the time) to load objects in $_SESSION['cache']  But, this particular bug will prevent the object from working in the second page. The variable is there, but there's nothing in it.

The easy work around is to upgrade PHP to 5.3, and it works like a charm, but at the moment 5.3 happens to be in alpha mode.

2. You cannot have a PDO object in as a member variable of a class stored in the ArrayObject if you want it to pass through sessions. You can store it if it's not going into a session, but if you want to cache like we're tying to do, make SURE you $_dbHandle="" wherever you need to.

3. My earlier post was just proof of concept. We have it working now so  UserCollection extends GenericCollectionAbstract.  and GenericCollectionAbstract implements the GenericCollectionInterface. GenericCollectionObject is the object stored in the GenericCollection's $arrayObject data, and is basically just a two property object that holds the ID of the object, and the object itself.

When all is said and done this works like a charm.

page 1 ->
$_SESSION['u'] = new UserCollection();
$_SESSION['u']->getObject(1, $dbWW);
page-2->
echo $_SESSION['u']->getObject(2, $dbWW)->getProperty('email');

And of course, getProperty() is from my user class.

my UserCollecton->getObject overwrite method is as follows:
public function getObject($_id, $_dbHandle){
		//error_log('trying to get object');
		if (parent::objectExists($_id)){
			return parent::getObject($_id, $_dbHandle);
			error_log('returning object');
		}
		else{
			//error_log('collecting new user');
			$_tempUser = new User();
			if ($_tempUser->populateByID($_id, $_dbHandle)){
				parent::addObject($_id, $_tempUser);
				if (parent::objectExists($_id)) {
					$_return = parent::getObject($_id);
				}
				else $_return = "";
			}
			else {
				$_return = "";		
			}
			$this->dbHandle=""; //This has to be done, otherwise it's stored in the object as a private var
								//and it will break the object if it resides in a session.
			return $_return;
		}

Shoot me an email if you have any questions.
enjoy.!
----
Server IP: 209.41.74.194
Probable Submitter: 199.229.1.111
----
Manual Page -- http://www.php.net/manual/en/class.arrayobject.php
Edit        -- https://master.php.net/note/edit/86249
Del: integrated  -- https://master.php.net/note/delete/86249/integrated
Del: useless     -- https://master.php.net/note/delete/86249/useless
Del: bad code    -- https://master.php.net/note/delete/86249/bad+code
Del: spam        -- https://master.php.net/note/delete/86249/spam
Del: non-english -- https://master.php.net/note/delete/86249/non-english
Del: in docs     -- https://master.php.net/note/delete/86249/in+docs
Del: other reasons-- https://master.php.net/note/delete/86249
Reject      -- https://master.php.net/note/reject/86249
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.