note 86249 modified in class.arrayobject by felipe
| From: | felipe@php.net | Date: | Thu, 16 Oct 2008 01:09:06 +0000 |
| Subject: | note 86249 modified in class.arrayobject by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145397@lists.php.net to get a copy of this message | ||
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:
<?php
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.!
--was--
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.!
http://php.net/manual/en/class.arrayobject.php