Класс LengthException

(PHP 5 >= 5.1.0)

Введение

Создается исключение, если длина является недопустимой.

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

LengthException extends LogicException {
/* Наследуемые методы */
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 )
}

Коментарии

protected static function isbnChecksum($input)
    {
        // We're calculating check digit for ISBN-10
        // so, the length of the input should be 9
        $length = 9;
        if (strlen($input) !== $length) {
            throw new \LengthException(sprintf('Input length should be equal to %d', $length));
        }
        $digits = str_split($input);
        array_walk(
            $digits,
            function (&$digit, $position) {
                $digit = (10 - $position) * $digit;
            }
        );
        $result = (11 - array_sum($digits) % 11) % 11;
        // 10 is replaced by X
        return ($result < 10)?$result:'X';
    }
2017-01-26 14:23:03
http://php5.kiev.ua/manual/ru/class.lengthexception.html

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