• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • OutOfRangeException()

    (PHP 5 >= 5.1.0, PHP 7)

    简介

    Exception thrown when an illegal index was requested. This represents errors that should be detected at compile time.

    类摘要

    OutOfRangeExceptionextendsLogicException{/*继承的属性*/protectedstring $message;protectedint $code;protectedstring $file;protectedint $line;/*继承的方法*/
    finalpublicException::getMessage(void): string
    finalpublicException::getPrevious(void): Throwable
    finalpublicException::getCode(void): int
    finalpublicException::getFile(void): string
    finalpublicException::getLine(void): int
    finalpublicException::getTrace(void): array
    finalpublicException::getTraceAsString(void): string
    publicException::__toString(void): string
    finalprivateException::__clone(void): void
    }
    I see this in this way:
    By definiton, OutOfRangeException should be use to when potential problem is logical - occurs because of wrong code or definition. OutOfBoundsException is for runtime.
    Example (see also note in "OutOfBoundsException class" article):
    <?php
    function prepareData(PDOStatement $s) {
      $x = $s->fetch();
      if (!isset($x['secretColumn'])) 
        throw new OutOfRangeException ("Secret column doesn't exist! Verify table definition and query.");
    }
    Exemple :
    $calendar = new Calendar();
    $calendar->getMonth(15);