PHP | date_get_last_errors()函数

date_get_last_errors()函数是PHP中的一个内置函数,用于返回警告和错误。此函数用于解析日期/时间字符串,并返回一组警告和错误。

null

语法:

  • 程序风格:
    array date_get_last_errors( void )
  • 面向对象风格:
    array DateTime::getLastErrors( void )

参数: 此函数不接受任何参数。

返回值: 此函数返回一个数组,其中包含有关警告和错误的信息。

下面的程序演示了PHP中的date_get_last_errors()函数:

项目1:

<?php
$date = date_create();
print_r(date_get_last_errors());
?>


输出:

Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 0
    [errors] => Array
        (
        )

)

项目2:

<?php
try {
$date = new DateTime( 'vgdgh' );
}
catch (Exception $e ) {
// For demonstration purposes only...
print_r(DateTime::getLastErrors());
}
?>


输出:

Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 1
    [errors] => Array
        (
            [0] => The timezone could not be found in the database
        )

)

相关文章:

参考: http://php.net/manual/en/datetime.getlasterrors.php

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享