PHP array Reference Bug?

ali-23

New Member
With PHP is it even Possible to Pass arrays by Reference ? or its a Bug Only for Me. \[code\]class MyStack{ private $_storage = array(); public function push(&$elem){//See I am Storing References. Not Copy $this->_storage[] = $elem; } public function pop(){ return array_pop($this->_storage); } public function top(){ return $this->_storage[count($this->_storage)-1]; } public function length(){ return count($this->_storage); } public function isEmpty(){ return ($this->length() == 0); }}?><?php$stack = new MyStack;$c = array(0, 1);$stack->push($c);$t = $stack->top();$t[] = 2;echo count($stack->top());?>\[/code\]Expected Result:\[code\]3\[/code\]But The Output is: \[code\]2\[/code\]
 
Back
Top