php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67402 DateTime cannot be converted to string
Submitted: 2014-06-09 16:25 UTC Modified: 2014-06-09 16:28 UTC
From: larene at pictordesign dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Red Hat Lynix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: larene at pictordesign dot com
New email:
PHP Version: OS:

 

 [2014-06-09 16:25 UTC] larene at pictordesign dot com
Description:
------------
---
From manual page: http://www.php.net/function.date-create
---
Putting this in my code:
$offer_end = new DateTime('06/06/2014');

Results in this error:
[Mon Jun 09 11:16:31 2014] [error] [client 70.34.10.173] PHP Catchable fatal error:  Object of class DateTime could not be converted to string in /home/test455/www/test455.fsreloading.com/fsadmin/emailSpecialOffers.php on line 147, referer: https://test.fsreloading.com/fsadmin/emailSpecialOffers.php

Test script:
---------------
$offer_end = new DateTime('06/06/2014');


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-09 16:28 UTC] aharvey@php.net
-Summary: PHP 5.2.17 +Summary: DateTime cannot be converted to string -Status: Open +Status: Not a bug -Type: Documentation Problem +Type: Bug -Package: Performance problem +Package: Date/time related
 [2014-06-09 16:28 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Presumably somewhere after this line, you are using $offer_end in a context where PHP will attempt to convert it to a string (such as an echo statement). DateTime objects (intentionally) do not implement a __toString() method, and cannot be converted to string.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC