Page 1 of 1
Persistent objects in PHP?
Posted: Sun Oct 19, 2003 6:28 am
by LonelyProgrammer
Hi,
Just wondering about the OOP aspect of PHP. Say I create an object from a class in one PHP page - can I pass it to another PHP page through POST or GET, or do I have to recreate the object from the class again?
Thanks in advance!
Posted: Sun Oct 19, 2003 6:38 am
by markl999
You could serialize() the object and pass it via GET/POST but it can be quite ugly. It's better to store the object in a session, like $_SESSION['obj'] = $obj;
When storing objects in sessions don't forget you must define the class before session_start(), i.e include 'theclassfile.php'; session_start() and not session_start(); include 'theclassfile.php';

Posted: Sun Oct 19, 2003 8:06 am
by jollyjumper
Hi Lonely programmer,
Do you know if this method is also possible with the result of a mysql_query? I've tried it once in a similair way, but it didn't work.
Greetz Jolly.
Posted: Sun Oct 19, 2003 8:08 am
by volka
you cannot store the resource identifier in sessions
(ok, you can, but only the string representation is stored and cannot be retrieved as resource handle)
Posted: Sun Oct 19, 2003 8:13 am
by jollyjumper
Hi Volka,
Thank you for your reply. Good to know, so I won't spend any more time on this
Greetz Jolly.