PHP.mk документација

OutOfRangeException

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

class.outofrangeexception.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека class.outofrangeexception.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
OutOfRangeException

Референца за `class.outofrangeexception.php` со подобрена типографија и навигација.

class.outofrangeexception.php

Класата OutOfRangeException

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Вовед

Исклучок што се фрла кога е побаран нелегален индекс. Ова претставува грешки што треба да се откријат во време на компајлирање.

Синопсис на класата

class OutOfRangeException extends LogicException {
/* Наследени својства */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
/* Наследени методи */
public Exception::__construct(string $message = "", int $code = 0, ?Проверува тврдење $previous = null)
final public Exception::getCode(): int
final public Exception::getFile(): string
final public Exception::getLine(): int
final public Exception::getTrace(): array
}

Белешки од корисници 4 белешки

Јакуб
пред 8 години
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.");
}
Бесплатно
пред 5 години
I tried to write a snippet that would be detected at compile time, but was unable, apparently due to my PHP engine's interpreted nature. The creator(s) should have provided a usage example (for end-users) or pointed to PHP sources for an example of where/how it's used. None of the provided examples, to date, reflect an exception detected at compile time, as this class asserts.

IMO it's hopeful at best to expect a compiler to detect an illegal index in a dynamically-typed, typically JIT-executed, enviro. Since when is there a strict contract of what indexes should be considered "within range" and how would the compiler know about this contract? Also, how would we try/catch that in the compile phase?

SPL also provides the OutOfBounds exception. If this class, its parent, and OOB have little distinction, then does SPL need all 3?
евгениа дот шањон ат џимејл дот ком
пред 9 години
Exemple :

$calendar = new Calendar();
$calendar->getMonth(15);
anrdaemon на yandex точка ru
3 години пред
I would probably repeat @jacub's answer, but I see the distinction as following:

`OutOfBoundsException` you throw, when _you_ _set_ bounds and do not wish them to be crossed by an external entity, but they may be.
Example: you ask for a number in range [1, 6] and user input 0 or 7 or what else. You throw an exception indicating user error they could amend.

`OutOfRange` you throw, when you expect value within allowed boundary, but actual operation fails.
Example: You are trying to access external API call using information provided by the API itself, and it suddenly tell you that the reference key is not pointing to a valid object. You throw an exception indicating internal failure that the user is unable to correct.

In both cases, the key word is "you throw". Both exceptions are generated at runtime, but the latter describes a situation that should not happen, ever, if a system is configured correctly.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.