fork download
  1. <?php
  2. class ReadingList
  3. {
  4. protected $stack;
  5. protected $limit;
  6. public function __construct($limit = 10) {
  7. $this->stack = array();
  8. $this->limit = $limit; }
  9. public function push($item) {
  10. if (count($this->stack) < $this->limit) {
  11. array_unshift($this->stack, $item); } else {
  12. throw new RunTimeException('Stack is full!'); }
  13. }
  14. public function pop() {
  15. if ($this->isEmpty()) {
  16. throw new RunTimeException('Stack is empty!');
  17. } else {
  18. return array_shift($this->stack); }
  19. }
  20. public function top() {
  21. return current($this->stack); }
  22. public function isEmpty() {
  23. return empty($this->stack); }
  24. }
  25. $stack = new ReadingList();
  26. $stack -> push ();
  27. $stack -> push ();
  28. $stack -> push ();
  29. $stack -> push ();
  30.  
  31. echo $stack -> isEmpty ();
Runtime error #stdin #stdout #stderr 0.03s 23700KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function ReadingList::push(), 0 passed in /home/nf97oA/prog.php on line 26 and exactly 1 expected in /home/nf97oA/prog.php:9
Stack trace:
#0 /home/nf97oA/prog.php(26): ReadingList->push()
#1 {main}
  thrown in /home/nf97oA/prog.php on line 9