Page 1 of 1

Global Object Space / persistent objects in php?

Posted: Thu Jul 24, 2003 8:16 am
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

Posted: Thu Jul 24, 2003 11:58 am
by AVATAr
i think the only way is to use sessions ;)

Posted: Thu Jul 24, 2003 2:32 pm
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 ;-)