note 127255 added to class.underflowexception

From: Date: Mon, 11 Jul 2022 11:01:00 +0000
Subject: note 127255 added to class.underflowexception
Groups: php.notes 
Request: Send a blank email to php-notes+get-218957@lists.php.net to get a copy of this message
The most typical usage is with stack, queue or collection, for example when you queue tasks, make call stack or manipulate JSON, XML, etc. elements. As other exepctions of RuntimeException class, this type of error can't be detected in (for example) your IDE or compiler. <?php // Functions declared above $f1 = function() { setTypeControl('username');}; $f2 = function() { setTypeControl('userpass');}; $f3 = function() { setButton('Add');}; $f4 = function() { setButton('OK');}; $tasks = new class { private $list; // Create internal queue public function __construct() { $this->list = new SplQueue; } // Add to queue public function add(callable $func) { $this->list->enqueue($func); } // Delete from queue and execute public function do() { if ($this->list->isEmpty()) { throw new UnderflowException; } else { call_user_func($this->list->dequeue()); } } }; $tasks->add($f1); $tasks->add($f2); $tasks->add($f3); $tasks->add($f4); $tasks->do(); // Field username is created $tasks->do(); // Field userpass is created $tasks->do(); // Button Add is created $tasks->do(); // Button OK is created $tasks->do(); // Fatal error: Uncaught UnderflowException in ... ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.12.131 (proxied: 37.30.108.154) ---- Manual Page -- https://php.net/manual/en/class.underflowexception.php Edit -- https://main.php.net/note/edit/127255 Del: integrated -- https://main.php.net/note/delete/127255/integrated Del: useless -- https://main.php.net/note/delete/127255/useless Del: bad code -- https://main.php.net/note/delete/127255/bad+code Del: spam -- https://main.php.net/note/delete/127255/spam Del: non-english -- https://main.php.net/note/delete/127255/non-english Del: in docs -- https://main.php.net/note/delete/127255/in+docs Del: other reasons-- https://main.php.net/note/delete/127255 Reject -- https://main.php.net/note/reject/127255 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218957) next »