ID:               40799
 Comment by:       none at mialinator dot com
 Reported By:      oliver dot graetz at gmx dot de
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: any
 PHP Version:      5.2.1
 New Comment:

just fix datetime!


Previous Comments:
------------------------------------------------------------------------

[2007-03-14 03:51:50] oliver dot graetz at gmx dot de

Description:
------------
Yes, I read the upgrade guide and the other bug reports regarding this
topic so this is not a bug report but a plea for reconsideration.

I really like that finally __toString() works in every situation but
the inability to output object instances without __toString() defined is
just too annoying. PHP preaches the KISS principle and on this issue the
language is breaking its own rules.

First of all, there are engine internal classes where the programmer is
unable to provide a __toString method. Subclassing all of these classes
upon usage just "to be on the safe side" is nonsense. If object output
can't be changed to provide a fallback if __toString() is missing then
at least all engine internal classes should implement their own default
output.

Secondly, for safety many programmers might be tempted to make all
classes extend a common superclass just "to be on the safe side". This
is braindead for the sake of any OOP concept but I already see some guys
on the horizon ready to do it.

And at last: There are so many convenient functions that just break if
their input contains "problem objects". It just makes no sense that PHP
forces me to implement an "object safe" version of implode()! I just had
to do that and the loss of performance makes me shudder. Rasmus once
said that PHP should only be a frontend for "PHP templates" that make
use of as much precompiled code as possible. So why are these
"templates" forced to implement ever more stuff in the userland?

Suggestions:

- at least implement default output for all engine internal classes

- change __toString() to have a fallback, even "[__toString() missing]"
improves on the current situation

-- if this isn't POSSIBLE: PLEASE clearly state why at prominent places
in the documentation.

-- if this isn't WANTED: make it configurable or better, add a magic
function, for example __tostring_fallback(), which should return a
string. If it doesn't exist or doesn't return a string: go ahead raising
the recoverable error! Abusing an error handler to do this is NOT a
solution.


Reproduce code:
---------------
<?php
echo new DateTime();
/*
 * How about this yielding the ISO formatted date or a timestamp?
 * Possibly even as debug output like
 * 
 * [DateTime object: 2004-02-12T15:19:21+00:00]
 * 
 * Definitely better than raising an error!
 */


Expected result:
----------------
some output and the script continuing

Actual result:
--------------
PHP Catchable fatal error:  Object of class DateTime could not be
converted to string in C:\test.php on line 2

Catchable fatal error: Object of class DateTime could not be converted
to string in C:\test.php on line 2


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40799&edit=1

Reply via email to