本文整理匯總了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);
}