Re: [PHP-DEV] wacky object idea From: Andi Gutmans (andi <email protected>)
Date: 08/28/00

At 13:23 28/08/00 -0400, Chuck Hagenbuch wrote:
>Quoting Andrei Zmievski <andrei <email protected>>:
>
> > This is one of the times when I completely agree with Andi. We have
> > __string_value method support and I suppose it's a nice enough feature
> > for debugging, but I don't see it being used for much more than that.
> > Adding other kinds of automatic object conversions is just going to lead
> > to more mess. Andi is right when he says that using interfaces would be
> > a better approach.
>
>Ok... I guess the simple answer is I disagree with you. Sure, interfaces
>would be good. How do you suggest we implement them in PHP?
>
>__string_value is great for writing objects that need to be displayed - just
>echo the object, and it does the right thing. Readability is certainly a
>concern, but that's the kind of thing an object should know how to do.
>
>So, in terms of readability, if I can make sure that an object evaluates to
>false, I can do this:
>
>if ($obj->methodThatMightFail()) {}
> or
>$res = $obj->methodThatMightFail();
>if ($res) {}
>
>Instead of:
>$res = $obj->methodThatMightFail();
>if (is_object($res) && (getclass($res) == 'PEAR_Exception')) { // failed }
>
>
>Having real exceptions would solve this also. Or having some way to enforce
>strong typing without checking the type returned from every single method
>call.
>
>I'm curious what you think of these assorted comments. Do you think I should
>be using a different language? Should I be writing the isobject() &&
>getclass() checks on every function call? How do you suggest we solve these
>problems?

Do I think you should be using a different language? Well it depends what
you are looking for. If you are looking for operator overloading I think
you should use C++. If you are looking for a fully object oriented strongly
typed programming language you should use Java. If you are looking for a
scripting language you should use PHP.
Yes, there are things that can be improved. Some things can't unless we
turn PHP into what it wasn't meant to be (strongly typed and so on).
Do I think you should have to write isobject() && getclass()? No it sucks.
All I said is lets not be hasty and decide on something we will regret.
Operator overloading (or something very similar we'd probably regret).
The best thing is to think about the current possibilites (what you can do
with PHP today), what you REALLY need (and not only what would be neat),
and then later on comes the hard part which is technical where we all have
to decide if it's possible/worth it/a wanted feature.
When dealing with a language there are a zillion of places you can get
bitten so we need to think well about how these kind of changes would
effect the language on a whole, the spirit of the language, and the
performance. When a user wants a feature he is not always aware of what
implications the feature could have.
My opinion: I would probably want to see exceptions instead of this "wacky
object idea". Exceptions has its own set of problems such as performance,
scope and so on, but we will give it an additional thought. At the same
time, we can all bring up other ideas but not 100% ppl will be pleased
because some ppl will want it one way some the other and the final result
will probably be either one or something in the middle.
Just keep it in mind while we'll all be discussing this and future features.

Andi

---
Andi Gutmans <andi <email protected>>
http://www.zend.com/

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>