Persistent objects in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Persistent objects in PHP?

Post 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!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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';

;)
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Volka,

Thank you for your reply. Good to know, so I won't spend any more time on this :-)

Greetz Jolly.
Post Reply