PHP: Set reference to a class as a constant...?
<p>I have a set of defined constants, and for some I'm serializing new instances of a class and setting as a constant (probably not the best idea, I know...), the problem is that when information changes in the instance of the class, it doesn't update the referenced memory that was declared in the constant... I know a constant cannot be altered, but isn't it really just pointing to a block of memory and when that memory information is changed, so should the returning value of the constant? Well before I confuse anyone with what I said, I'll just show you what I have done:</p>

<pre><code>&lt;?php
    class Collection {
        var $items = array();

        public function __construct() { }

        public function add($val) {
            array_push($this-&gt;items, $val);
        }

        public function dump() {
            var_dump($this-&gt;items);
        }
    }

    $collection = new Collection();
    define('COLLECTION', serialize(&amp;$collection));
    unserialize(COLLECTION)-&gt;add('test item 1');
    unserialize(COLLECTION)-&gt;add('test item 2');
    unserialize(COLLECTION)-&gt;dump();
    /* It will end up dumping this:
       array(0) { }
     */
?&gt;
</code></pre>

<p>Now the reason why I'm doing this is because I'll be using these constants in many(30+) different php files, inside many functions, I know this can be accomplished by simple just using the variable and using <code>global $variable;</code> in every function, but I'm trying to avoid it since most servers have globals turned off. Please tell me if there is a better way to approach it aswell. <br /><br /> - Thanks!<br /> &nbsp;&nbsp;Nadeem</p>
