mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

This is a comprehensive refactoring of the error mechanism of the Intl extension. By moving the prefixing of the current method/function being executed to actual error message creation by accessing the execution context, we get the following benefits: - Accurate error messages indicating *what* call caused the error - As we *always* "copy" the message, the `copyMsg` arg becomes unused, meaning we can reduce the size of the `intl_error` struct by 4 bytes. - Saving it as a zend_string means we know the length of the message - Remove the need to pass around a "function name" `char*` across multiple calls - Use Intl's exception mechanism to generate exceptions for constructor call - This removes the need for replacing the error handler - Which didn't do anything anyway in silent mode, which required throwing non-descriptive exceptions
60 lines
2.5 KiB
PHP
60 lines
2.5 KiB
PHP
--TEST--
|
|
IntlDateFormatter::formatObject(): error conditions
|
|
--EXTENSIONS--
|
|
intl
|
|
--INI--
|
|
intl.default_locale=pt_PT
|
|
date.timezone=Europe/Lisbon
|
|
--FILE--
|
|
<?php
|
|
|
|
class A extends IntlCalendar {function __construct(){}}
|
|
|
|
class B extends DateTime {function __construct(){}}
|
|
|
|
$cal = IntlCalendar::createInstance();
|
|
|
|
try {
|
|
var_dump(IntlDateFormatter::formatObject(new B));
|
|
var_dump(intl_get_error_message());
|
|
} catch (Throwable $e) {
|
|
echo $e::class, ': ', $e->getMessage(), "\n";
|
|
}
|
|
|
|
var_dump(IntlDateFormatter::formatObject(new stdclass));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject(new A));
|
|
var_dump(intl_get_error_message());
|
|
|
|
var_dump(IntlDateFormatter::formatObject($cal, -2));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject($cal, array()));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject($cal, array(1,2,3)));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
|
|
var_dump(intl_get_error_message());
|
|
var_dump(IntlDateFormatter::formatObject($cal, ""));
|
|
var_dump(intl_get_error_message());
|
|
|
|
?>
|
|
--EXPECT--
|
|
DateObjectError: Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
|
|
bool(false)
|
|
string(130) "IntlDateFormatter::formatObject(): the passed object must be an instance of either IntlCalendar or DateTimeInterface: U_ZERO_ERROR"
|
|
bool(false)
|
|
string(112) "IntlDateFormatter::formatObject(): bad IntlCalendar instance: not initialized properly: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(97) "IntlDateFormatter::formatObject(): the date/time format type is invalid: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(108) "IntlDateFormatter::formatObject(): bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(108) "IntlDateFormatter::formatObject(): bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(130) "IntlDateFormatter::formatObject(): bad format; the date format (first element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(131) "IntlDateFormatter::formatObject(): bad format; the time format (second element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
|
|
bool(false)
|
|
string(80) "IntlDateFormatter::formatObject(): the format is empty: U_ILLEGAL_ARGUMENT_ERROR"
|