Re: DB_DataObject

From: Date: Thu, 27 Feb 2003 01:57:35 +0000
Subject: Re: DB_DataObject
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3986@lists.php.net to get a copy of this message
Limbourg Arnaud wrote:
In the doc there is
    $options = &PEAR::getStaticProperty('DB_DataObject', 'options');
        $config  = parse_ini_file('DataObjects/conf_dataobjects.ini', true);
        $options = $config['DB_DataObject'];
Do i just need to call those lines once per execution ? yeah - otherwise dataobjects has no idea where the table config etc. are.
obviously you could put it in sessions - but since parse_ini_file is probably just as fast as the php serializer you're not going to see an amazing amount of difference... The &PEAR... gets by reference, so that any value you set to $options really gets set to $properties['DB_DataObject']['options'] below.. - and can hence be fetched at any point later.. technically you may want to unset($options); after that to stop it getting changed.. - but I've never tested that, as that code is usually in a function somewhere..
Can you explain how this works, i don't quite get it.
the code in PEAR::getStaticProperty is very simple : function &getStaticProperty($class, $var)
    {
        static $properties;
        return $properties[$class][$var];
    }
so basically it makes storing a variable possible without knowing that the class will be loaded.. The alternative to this is to set global variables : eg. $_DB_DATAOBJECT['config'] = ..... however since there are times when you want to load the config and not load DataObjects that would fail as DataObjects must (for security reasons) always reset it's Globals on Loading. The other reason for doing it is that it's reasonably easy to integrate into any other Configuration Mechanisims.. Regards Alan

« previous php.pear.general (#3986) next »