Bug #71954 [Com]: array_unique and datetimes

From: Date: Sun, 05 Mar 2017 08:26:06 +0000
Subject: Bug #71954 [Com]: array_unique and datetimes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207693@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71954&edit=1 ID: 71954 Comment by: kordosoft25 at gmail dot com Reported by: marcelloh at gmail dot com Summary: array_unique and datetimes Status: Not a bug Type: Bug Package: *General Issues Operating System: win10 PHP Version: 7.0.5 Block user comment: N Private report: N New Comment: That is a bug... you can't change the status of this issue to: Not a bug when it returns fatal error... Previous Comments: ------------------------------------------------------------------------ [2016-04-04 08:14:15] requinix@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. The test2 item is a DateTime object. It cannot be converted to a string automatically, which is what array_unique will try to do by default. ------------------------------------------------------------------------ [2016-04-04 08:01:20] marcelloh at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=71954&edit=1

« previous php.bugs (#207693) next »