Reply to Re: Object of class Person could not be converted to string

Your name:

Reply:


Posted by Jerry Stuckle on 06/12/07 15:06

gosha bine wrote:
> On 12.06.2007 10:49 Jerry Stuckle wrote:
>> gosha bine wrote:
>>> On 11.06.2007 20:58 Schraalhans Keukenmeester wrote:
>>>>
>>>> Imho implicit obj2str conversion is meaningless, and though I have
>>>> abused
>>>> the construct myself a few times I am glad they corrected this
>>>> behaviour.
>>>> Having to define your own stringifier forces you to think about and
>>>> implement what is logically the proper meaning of a conversion to an
>>>> otherwise incompatible type.
>>>
>>> That's exactly the point Zend developers are constantly missing. It
>>> is not the responsibility of language designers to remove constructs
>>> that may seem "useless" to them. An application programmer is the one
>>> who decides which syntax is appropriate for her particular task. The
>>> job of the language designer is to provide clean and consistent
>>> mechanism for generating any possible expression, including "useless"
>>> ones. You don't let a taxi driver decide where you're going to go, do
>>> you?
>>>
>>
>> No, but you let a taxi driver decide how you get there.
>
> You are not trying to refute a _metaphor_, are you? ;)
>

Sure! :-)

>>
>>> As to this specific case, removal of implicit toString is especially
>>> stupid, because _every other_ type in php and _every other_
>>> comparable programming language supports it.
>>>
>>
>> No, every other type in php doesn't support it. When was the last
>> time you tried to convert an object to an int, for instance?
>
> I meant, every other php type supports implicit toString:
>
> echo 123; - works
> echo array(1, 2, 3); - works
> echo fopen('blah', 'r'); - works
>
> echo new Blah(); - DOES NOT work
>

Sure, and every other type is built in.

>>
>> And as for every other comparable programming language - no they don't.
>
> Most languages support implicit toString for objects:
>
> alert(new Blah()) - works in javascript
> puts Blah.new - works in ruby
> print Blah() - works in python
> System.out.println(new Blah()) - works in java
>
> echo new Blah() - DOES NOT work in php
>

Well, for instance, C++ doesn't support it. And I've found Java's
default tostring() function to be particularly useless. That's why I
overload it in every class where I'm going to need it.

> Are you saying other languages' designers care less about their
> programmers? Why do they allow such a "useless" thing?
>

I'm not saying anything about any other languages' designers. All I'm
saying is I find it particularly useless.

>> But who cares? Other languages have features PHP doesn't have, and
>> PHP has features they don't have. It's comparing apples and oranges.
>
> Comparing programming languages and technologies is always productive,
> there's always something to learn from each other.
>

Sure. But different languages have different syntax and different
features. That's why they're different languages. No one language is
good for everything.

>>
>> Personally, I've found the silent conversion allows for sloppy
>> programming and problems (like the one which started this thread).
>> I'm glad to see the implicit conversion is gone.
>
> What exactly are the problems which are solved by removing the silent
> conversion?
>

It makes you think about the implementation of the _tostring() method -
and specifically stops programming errors like which started this thread.

>>
>> But if you really want it, the developers left a way for you to do so.
>> Good for them.
>>
>
> An object without toString was converted to "object #x" or similar when
> being printed. So was the behaviour prior to 5.2. Useless or not, it
> simply worked. Now, it's broken and there's no way to make it work again.
>
>

Yea, it was broken before. "object #x" is real descriptive, isn't it?
And of course, you still have var_dump() and print_r() to help you,
don't you?

I just see absolutely no problem with removing the default. I would
have more of a problem if they didn't allow the programmer a means to
implement it, however.

But heck - I seldom used it. Last time I can think of using it was for
other than debugging was in a simple Point class, where it would print
"(x,y)" or "(r, theta)", depending on whether I was using Cartesian or
Polar coordinates.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация