|
| 1 | +--TEST-- |
| 2 | +Intl timezone argument APIs reject non-stringable objects with TypeError |
| 3 | +--EXTENSIONS-- |
| 4 | +intl |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +function dump_exception(callable $cb): void { |
| 9 | + try { |
| 10 | + $cb(); |
| 11 | + } catch (Throwable $e) { |
| 12 | + echo $e::class, ': ', $e->getMessage(), PHP_EOL; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +$std = new stdClass(); |
| 17 | +$calendar = IntlCalendar::createInstance(); |
| 18 | +$formatter = new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::NONE); |
| 19 | + |
| 20 | +dump_exception(fn() => intlcal_create_instance($std)); |
| 21 | +dump_exception(fn() => IntlCalendar::createInstance($std)); |
| 22 | +dump_exception(fn() => intlcal_set_time_zone($calendar, $std)); |
| 23 | +dump_exception(fn() => $calendar->setTimeZone($std)); |
| 24 | +dump_exception(fn() => new IntlGregorianCalendar($std)); |
| 25 | +dump_exception(fn() => datefmt_create(null, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $std)); |
| 26 | +dump_exception(fn() => IntlDateFormatter::create(null, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $std)); |
| 27 | +dump_exception(fn() => new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $std)); |
| 28 | +dump_exception(fn() => datefmt_set_timezone($formatter, $std)); |
| 29 | +dump_exception(fn() => $formatter->setTimeZone($std)); |
| 30 | + |
| 31 | +?> |
| 32 | +--EXPECT-- |
| 33 | +TypeError: intlcal_create_instance(): Argument #1 ($timezone) Object of class stdClass could not be converted to string |
| 34 | +TypeError: IntlCalendar::createInstance(): Argument #1 ($timezone) Object of class stdClass could not be converted to string |
| 35 | +TypeError: intlcal_set_time_zone(): Argument #2 ($timezone) Object of class stdClass could not be converted to string |
| 36 | +TypeError: IntlCalendar::setTimeZone(): Argument #1 ($timezone) Object of class stdClass could not be converted to string |
| 37 | +TypeError: IntlGregorianCalendar::__construct(): Argument #1 ($timezoneOrYear) Object of class stdClass could not be converted to string |
| 38 | +TypeError: datefmt_create(): Argument #4 ($timezone) Object of class stdClass could not be converted to string |
| 39 | +TypeError: IntlDateFormatter::create(): Argument #4 ($timezone) Object of class stdClass could not be converted to string |
| 40 | +TypeError: IntlDateFormatter::__construct(): Argument #4 ($timezone) Object of class stdClass could not be converted to string |
| 41 | +TypeError: datefmt_set_timezone(): Argument #2 ($timezone) Object of class stdClass could not be converted to string |
| 42 | +TypeError: IntlDateFormatter::setTimeZone(): Argument #1 ($timezone) Object of class stdClass could not be converted to string |
0 commit comments