great Knuth man :eek: Php was written in C, not the other wasy around 😃
php has no operator overloading... (at least i don't think, please email me if im wrong)
for the specific example you gave there is no need to use anything but the array() type... so was this just for practice or are you confused on what you should do?
you are stuck with java style get() and set() functions instead... here is an example that works...
<?php
$mArrayList = new CArrayList();
$mArrayList->push('A');
$mArrayList->push('B');
$mArrayList->push('C');
echo $mArrayList->get(0);
echo $mArrayList->get(1);
echo $mArrayList->last();
echo $mArrayList->pop();
echo $mArrayList->pop();
echo $mArrayList->pop();
Class CArrayList
{
var $m_ArrayList;
function CArrayList()
{
$this->m_ArrayList = array();
}
function push( $item )
{
$this->m_ArrayList[] = $item;
}
function pop()
{
return array_pop( $this->m_ArrayList );
}
function get( $index=NULL )
{
if ( $index === NULL ) {
$index = count($this->m_ArrayList)-1;
}
return $this->m_ArrayList[$index];
}
function last()
{
return end($this->m_ArrayList);
}
}
?>