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:
<?php
class Collection {
var $items = array();
public function __construct() { }
public function add($val) {
array_push($this->items, $val);
}
public function dump() {
var_dump($this->items);
}
}
$collection = new Collection();
define('COLLECTION', serialize(&$collection));
unserialize(COLLECTION)->add('test item 1');
unserialize(COLLECTION)->add('test item 2');
unserialize(COLLECTION)->dump();
/* It will end up dumping this:
array(0) { }
*/
?>
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 global $variable; 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.
- Thanks!
Nadeem