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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 08:01:35 2024 UTC