What you probably want is this:
class MyStack{
/* ... */
/* Store a non-reference */
public function push($elem) {
$this->_storage[] = $elem;
}
/* return a reference */
public function &top(){
return $this->_storage[count($this->_storage)-1];
}
/* ...*/
}
/* You must also ask for a reference when calling */
/* ... */
$t = &$stack->top();
$t[] = 2;
Artefacto
2010-08-27 17:24:26