All pastes #269800 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-06 20:47 UTC
rendered paste body
class Test {
	
	public $x = array();
	//public $test;
	
	function __get($i) 
	{
		if(isset($this->{$i})) {
			return($this->{$i});
		}
		elseif(isset($this->x[$i])) {
			pre('------GET------'.$i);
			pre($this->x[$i]);
			return($this->x[$i]);
		}
		else {
			return(NULL);
		}
	}
	
	function __set($i, $val)
	{
		pre('--------SET---------');
		if(isset($this->{$i})) {
			$this->{$i} = $val;
		}
		else {
			$this->x[$i] = $val;
		}
	}
}

$t = new Test();

$x = 5;
while($x>0) {
 	if(!is_array($t->test)) {
 		$t->test = array();
 	}
 	$t->test[3] = $x;
 	//array_push($t->test, $x);
 	$x--;
}
var_dump($t->test);