> [EMAIL PROTECTED] wrote: >> First of all, PHP's object model is most similar to the Java one, so >> Markus' comparisons make most sense in my eyes. > > The object model might be similar to Java (it's a very simple one which > I like) but the language is not and *should not be* IMHO. Java got much > too bloated and we should *not* make the same mistake with PHP. > (If anyone proposes inner classes in PHP then I'm outta here ;-)) Actually those are a 'modern/dynamic' aspect of Java (being pseudo-closures).
>> "modern dynamic" languages in that context, as for instance in Python >> there is no error handling but by using exceptions). > > Sorry but that's simply wrong. Python methods can return false or null > as much as PHP methods can. It might be a lot more _common_ to use > exceptions but there are options. And the exception part is the one I > don't like about Python anyway ;-) There is no such thing as E_* in PHP, that is my point. All kind of exceptional behaviour is covered by exceptions. Anyway, I'd prefer to dicuss on objective, rational arguments than on pure personal preference. I really know you dislike exceptions by now ;) >> Well, your point before was that it's used only about 10 times per >> library. You shouldn't worry too much about 'heavy constructs', then. > > But I do. Because every single PHP programmer now has to learn this new > construct for no good reason. Well, I suppose exceptions were added to the language for good reasons (even if you don't like them, as stated several times). >> Well, you handle errors in each case. Exceptions just simplify non-local >> propagation of errors, so I fail to see your point. > > Non-local propagation of error is a bogus concept IMHO. Because it only > really works in academic examples, everywhere else it just complicated > things. I've seen many projects (both commercial and non-commercial ones) which successfully used exceptions. Also, I definately miss exceptions in PHP4. Manual propagation of error in my eyes is both error-prone, tedious and slow. >> Yeah. And well, people should be able to rely on the idea of 'new' not >> returning NULL (at least in the common cases, i.e. in the design of the > > But they now have to expect new to throw an exception. How is that any > better? Sorry, no *I* fail to see your point. It improves code maintainability. Instead of if(!$foo=new Foo()) return ERROR; if(!$foo->doThis()) return ERROR; if(!$foo->doThat()) return ERROR; you simply do $foo=new Foo(); $foo->doThis(); $foo->doThat(); And yes, I *intentionally* omitted try/catch clauses, as there is no error _handling_ in the original code, either. Just a lot of overhead from manual propagation of error. >> This is interesting. Do you have any explanations of the apparent >> failure >> of exceptions for you, or any suggestions on how to improve them (like, >> by > > The concept of non-local handling of errors means you > a) Handle errors where they happen. You don't need exceptions for that > b) Handle errors on a global level (i.e. die). Not feasible in a lot of > cases and you don't need exceptions here either > c) You handle errors somewhere inbetween. Exceptions were added to be able to deal with error situations at the appropriate place (i.e. mostly for c) reasons). > [...] > The same problem more or less applies if you use traditional error > handling (i.e. you would ignore the failure result code of add) but my > point is that exceptions _seem_ to help but don't. So it seems that you dislike exceptions because they don't solve problems they were not designed to solve for. Maybe your point is also that, with exceptions, people have to change their way of understanding code snippets (always have to have exception safety in mind). This is not much different from failing to catch today's error return values or E_RRORS, though. Cheers, Michael P.S.: Python supports overriding __new__, too (as a class method). P.P.S.: How about adding a new_ to the standard library (well it could be doable in userland, too, I guess) which catches exceptions and returns NULL in the exception case? This would be a generic 'new' wrapper for code which doesn't use exceptions (not that I think it would be necessary, but if people keep demanding it..). -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php