本文整理汇总了PHP中DateTimeImmutable::getLastErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::getLastErrors方法的具体用法?PHP DateTimeImmutable::getLastErrors怎么用?PHP DateTimeImmutable::getLastErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::getLastErrors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateFromFormatFailure
public function testCreateFromFormatFailure()
{
$time = 'foo';
$immutable = DateTimeImmutable::createFromFormat(DateTime::RFC3339, $time);
$mutable = DateTime::createFromFormat(DateTime::RFC3339, $time);
$this->assertFalse($immutable);
$this->assertSame(DateTime::getLastErrors(), DateTimeImmutable::getLastErrors());
}
示例2: denormalize
/**
* {@inheritdoc}
*
* @throws UnexpectedValueException
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
$dateTimeFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : null;
if (null !== $dateTimeFormat) {
$object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data);
if (false !== $object) {
return $object;
}
$dateTimeErrors = \DateTime::class === $class ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors();
throw new UnexpectedValueException(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors:' . "\n" . '%s', $data, $dateTimeFormat, $dateTimeErrors['error_count'], implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors']))));
}
try {
return \DateTime::class === $class ? new \DateTime($data) : new \DateTimeImmutable($data);
} catch (\Exception $e) {
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
}
}
示例3: _getLastDateTimeImmutableErrorsStr
/**
* Get last error caused by DateTimeImmutable.
*
* @return string
*/
protected static function _getLastDateTimeImmutableErrorsStr()
{
$errors = \DateTimeImmutable::getLastErrors()["errors"];
return implode(", ", $errors);
}