<?php
class A
{
    private $count = 0;

    public function put($var){
        $this->count++;
        $count = $this->count;
        $this->$count = $var;
    }

    public function pop(){
        $count = $this->count;
        $var = $this->$count;
        $this->count--;
        return $var;
    }
}

$a = new A();
$a->put(5);
$a->put(8);
echo $a->pop() . PHP_EOL;
echo $a->pop();