Doc #71108 [NEW]: date_create() is NOT an alias for "new DateTime()"
| From: | public at grik dot net | Date: | Sun, 13 Dec 2015 10:46:27 +0000 |
| Subject: | Doc #71108 [NEW]: date_create() is NOT an alias for "new DateTime()" | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-12932@lists.php.net to get a copy of this message | ||
From: public at grik dot net
Operating system: irrelevant
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:date_create() is NOT an alias for "new DateTime()"
Description:
------------
---
From manual page: http://www.php.net/function.date-create
---
date_create() is NOT an alias, It is closer to be named a factory.
For the first hand, DateTime::__construct() can't be called, which is
obvious.
For another, there is a significant difference between date_create() and
"new DateTime()"
We write
if (!($DateTime = date_create('garbage'))){
//process error
}
but
try {
$DateTime = new DateTime('garbage');
}catch(Exception $E){
...
}
Test script:
---------------
$ php -r 'var_dump(date_create("garbage"));'
bool(false)
$ php -r 'var_dump(new DateTime("garbage"));'
Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct(): Failed to parse time string (garbage) at
position 0 (s): The timezone could not be found in the database' in
Command line code:1
Stack trace:
#0 Command line code(1): DateTime->__construct('garbage')
#1 {main}
thrown in Command line code on line 1
--
Edit bug report at https://bugs.php.net/bug.php?id=71108&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71108&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71108&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71108&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71108&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71108&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71108&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71108&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71108&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71108&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71108&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71108&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71108&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71108&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71108&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71108&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71108&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71108&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71108&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71108&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71108&r=mysqlcfg