Класс UnderflowException

(PHP 5 >= 5.1.0)

Введение

Создается исключение при попытке произвести недопустимую операцию над пустым контейнером. Например такую, как удаление элемента пустого контейнера.

Обзор классов

UnderflowException extends RuntimeException {
/* Наследуемые методы */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}

Коментарии

UnderflowException handles exceptions due to a value being too small to maintain precision, resulting in loss of accuracy. In PHP, this can occurs when using floats:

echo (1-0.9) // 0.1
echo (1-0.99) // 0.01
echo (1-0.999) // 0.001
echo (1-0.9999) // 9.9999999999989E-05
echo (1-0.99999) // 9.9999999999545E-06
echo (1-0.999999) // 1.0000000000288E-06
2017-01-26 15:40:37
http://php5.kiev.ua/manual/ru/class.underflowexception.html
Автор:
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 ...
2022-07-11 14:01:00
http://php5.kiev.ua/manual/ru/class.underflowexception.html

    Поддержать сайт на родительском проекте КГБ