Hi
I need to know how to keep instance of class. For example. I created
object:
$myObj = new Person();
ok, and then someone wants to go to the links page, and I want to keep
data which are created in myObj, for exmaple $myObj->age; $myObj->name;
etc. etc.
I thought about $serMyObj = serialize($myObj) and the put $serMyObj
data through POST, GET, or sth like that, and then GET it, but what if
the portal is big and i want to keep 50 objects in one session ?? put
data to the database and after that get it and every time someone is
redirecting to the another page, get form database ... 6 1240
Python wrote: Hi
I need to know how to keep instance of class. For example. I created object:
$myObj = new Person();
ok, and then someone wants to go to the links page, and I want to keep data which are created in myObj, for exmaple $myObj->age; $myObj->name; etc. etc.
I thought about $serMyObj = serialize($myObj) and the put $serMyObj data through POST, GET, or sth like that, and then GET it, but what if the portal is big and i want to keep 50 objects in one session ?? put data to the database and after that get it and every time someone is redirecting to the another page, get form database ...
Hi Python,
I may make more sense for you to use SESSION instead of passing info around
with POST and GET.
Read here: http://nl3.php.net/session
Be sure you read the about Objects and Session, because there are some
issues if you first start a session, and then declare the object.
First load the objectdefinition, then start the session, but that is all
explained at the php site.
Good luck.
Regards,
Erwin Moller
Python wrote: Hi
I need to know how to keep instance of class. For example. I created object:
$myObj = new Person();
ok, and then someone wants to go to the links page, and I want to keep data which are created in myObj, for exmaple $myObj->age; $myObj->name; etc. etc.
I thought about $serMyObj = serialize($myObj) and the put $serMyObj data through POST, GET, or sth like that, and then GET it, but what if the portal is big and i want to keep 50 objects in one session ?? put data to the database and after that get it and every time someone is redirecting to the another page, get form database ...
I think you answered your own question with this post... Use sessions.
You can serialize your object and store it in a session variable. Then
on the next script, make sure you include all the necessary include
files for the object classes before you unserialize. I'd personally use
sessions with custom handlers to utilize database tables for this, but
sometimes that is overkill and takes more resources.
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com
Justin Koivisto wrote: I think you answered your own question with this post... Use sessions. You can serialize your object and store it in a session variable. Then on the next script, make sure you include all the necessary include files for the object classes before you unserialize. I'd personally use sessions with custom handlers to utilize database tables for this, but sometimes that is overkill and takes more resources.
Just for reference (at least with PHP 4.3+) you don't need to
explicitely serialize/unserialize your objects for use in Sessions. You
can just do:
require_once("foo.class.php");
session_start();
if (!is_object($_SESSION["myfoo"])) {
$_SESSION["myfoo"] = new Foo();
}
$_SESSION["myfoo"]->bar();
Cheers,
Andy
Andy Jeffries wrote: Justin Koivisto wrote:
I think you answered your own question with this post... Use sessions. You can serialize your object and store it in a session variable. Then on the next script, make sure you include all the necessary include files for the object classes before you unserialize. I'd personally use sessions with custom handlers to utilize database tables for this, but sometimes that is overkill and takes more resources.
Just for reference (at least with PHP 4.3+) you don't need to explicitely serialize/unserialize your objects for use in Sessions. You can just do:
require_once("foo.class.php"); session_start(); if (!is_object($_SESSION["myfoo"])) { $_SESSION["myfoo"] = new Foo(); }
$_SESSION["myfoo"]->bar();
You would not believe the number of ISPs still running the 4.0 and 4.1
branches... However, it is good to point that out for those who have
access to newer versions. I had that in my message, but deleted it as
not to confuse the point.
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com
Justin Koivisto wrote: Just for reference (at least with PHP 4.3+) you don't need to explicitely serialize/unserialize your objects for use in Sessions. You can just do:
require_once("foo.class.php"); session_start(); if (!is_object($_SESSION["myfoo"])) { $_SESSION["myfoo"] = new Foo(); }
$_SESSION["myfoo"]->bar();
You would not believe the number of ISPs still running the 4.0 and 4.1 branches... However, it is good to point that out for those who have access to newer versions. I had that in my message, but deleted it as not to confuse the point.
I'm not sure if it actually worked in older versions, it's been a while
since I converted all my servers to 4.3...
I haven't got any older versions to try it on. Have you tried it on an
older version?
Cheers,
Andy
Andy Jeffries wrote: Justin Koivisto wrote:
Just for reference (at least with PHP 4.3+) you don't need to explicitely serialize/unserialize your objects for use in Sessions. You can just do:
require_once("foo.class.php"); session_start(); if (!is_object($_SESSION["myfoo"])) { $_SESSION["myfoo"] = new Foo(); }
$_SESSION["myfoo"]->bar(); You would not believe the number of ISPs still running the 4.0 and 4.1 branches... However, it is good to point that out for those who have access to newer versions. I had that in my message, but deleted it as not to confuse the point.
I'm not sure if it actually worked in older versions, it's been a while since I converted all my servers to 4.3...
I haven't got any older versions to try it on. Have you tried it on an older version?
I had done it once before and did have problems with objects in
sessions, but I don't remember what version of PHP it was - of course,
it could have been that server's setup as well. I've been making a point
of not developing for versions under 4.3 as of late, and soon will be
trying to push php5 much more. (When I've had some more time to play.)
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com This discussion thread is closed Replies have been disabled for this discussion. Similar topics
4 posts
views
Thread by Avi Kak |
last post: by
|
3 posts
views
Thread by Adam |
last post: by
|
11 posts
views
Thread by Kevin Prichard |
last post: by
|
15 posts
views
Thread by mr.peteryu |
last post: by
|
8 posts
views
Thread by a |
last post: by
|
reply
views
Thread by a |
last post: by
|
5 posts
views
Thread by JH |
last post: by
|
26 posts
views
Thread by momobear |
last post: by
|
3 posts
views
Thread by notnorwegian |
last post: by
|
23 posts
views
Thread by tonytech08 |
last post: by
| | | | | | | | | | |