Global Object Space / 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
jowestla
Forum Newbie
Posts: 3
Joined: Thu Jul 24, 2003 8:16 am

Global Object Space / persistent objects in php?

Post by jowestla »

Hi all,
i am actually developing a quite small php application (one of my first projects in php) and i face a problem i am not able to solve by myself, due to lack of experience.

The problem i face is hopefully quite simple:

i want to be able to refer to a once created instance of a class in script X also out of script Y:

my effort
script :init_all.php (included everywhere):
<?
if(!$GLOBAL_SYSTEM_ENGINE)
{
$GLOBAL_SYSTEM_ENGINE=& new system_engine();
}
?>

script x.php:

<?php
require(init_all.php);

[...]
?>

script y.php:

<?php
require(init_all.php);

[...]
?>


everytime x or y are executed, a new instance of system_engine is created. Thats exactly what i try to avoid.

Is there any way to handle global - only once created - class istances in multiple scripts? Maybe though an superglobal object-container or whatever?

ps: I do not want to use $_SESSION to store objects, too complicated, static and performance-killing i fear.

thanks for any hint

jochen
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

i think the only way is to use sessions ;)
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

You can serialize your object in XML file on HDD and keep filename in session ... but you still need session. And I think that PHP function serialize() will work faster than your oun function ;-)
Post Reply