Jonob Posted October 24, 2009 Share Posted October 24, 2009 Hi all, I have an array mapped to a value object. One of the items in the array is a PHP DateObject, and I need to format this field appropriately. When looping through the array, I pass this field to a function as follows: (simplified for expendiency) if (!is_null($date)) { return date_format($date, "Y-m-d"); } This works great, except for the case when the DateObject contains a null value - in this case the above function seems to always return the current date. I am guessing that this is because $date is not really null (i.e. it contains an object, even though the object is null), but I am not sure how to get around this. Any help greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/178836-dateobject-and-nulls/ Share on other sites More sharing options...
salathe Posted October 24, 2009 Share Posted October 24, 2009 There is no DateObject in the PHP core, is this a user-defined class or do you mean DateTime? Also, your code snippet only deals with the $date value being not null which won't affect any null value. Quote Link to comment https://forums.phpfreaks.com/topic/178836-dateobject-and-nulls/#findComment-943455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.