Bug #71954 [NEW]: array_unique and datetimes
| From: | marcelloh at gmail dot com | Date: | Mon, 04 Apr 2016 08:01:54 +0000 |
| Subject: | Bug #71954 [NEW]: array_unique and datetimes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200335@lists.php.net to get a copy of this message | ||
From: marcelloh at gmail dot com
Operating system: win10
PHP version: 7.0.5
Package: *General Issues
Bug Type: Bug
Bug description:array_unique and datetimes
Description:
------------
I have this array filled with all kinds of types.
Today I used a DateTime object in that array for the first time.
In my code there is this line:
$aUniqueValues = array_unique($aValues);
and there is an fatal error now:
Catchable fatal error: Object of class DateTime could not be converted
to string in MyClass.php on line 149
I can't find in the documentation
http://php.net/manual/en/function.array-unique.php
how to catch that error.
Test script:
---------------
$aValues = array();
$now = date('Y-m-d H:i:s');
$aValues['test1'] = $now;
$aValues['test2'] = DateTime::createFromFormat('Y-m-d H:i:s', $now);
$aUniqueValues = array_unique($aValues);
Expected result:
----------------
I would expect no fatal error, but a normal unique array.
I think, it is a bit strange that I can make a string out of a DateTime
object, and that the code behind array_unique can't do that.
--
Edit bug report at https://bugs.php.net/bug.php?id=71954&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71954&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71954&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71954&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71954&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71954&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71954&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71954&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71954&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71954&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71954&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71954&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71954&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71954&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71954&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71954&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71954&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71954&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71954&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71954&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71954&r=mysqlcfg