Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c

php.internals

Andi Gutmans

22 years ago
At 08:12 AM 2/13/2004 -0500, Sterling Hughes wrote:
> > zeev Thu Feb 12 05:24:40 2004 EDT > > > > Modified files: > > /ZendEngine2 zend_default_classes.c zend_default_classes.h > > zend_execute.h zend_execute_API.c > > Log: > > Exceptions updates: > > > > - Enforce exceptions to be derived from class Exception. This allows > > users to perform catch-all. It's not yet complete, so don't get > > comfortable with it just yet :) Updates are coming soon. > >This is imho wrong. Exception is not a requirement, but an optional >thing. For the most part, all user exceptions should inherit from >"Exception," but that same onus is not on extension space exceptions, or >exceptions that are meant to be thrown out of bounds. > >Ie, you should be able to have: > >try { > foo(); >} catch (Exception $e) { >} catch (InternalException $ie) { >} > >What is the reasoning for this new change?
The reasoning is that it allows users to do a catch-all (which otherwise we'd add to the language syntax). It also adds cleanliness to the Exception hierarchy and allows PHP code to interact with PHP code which isn't written by the developer knowing that there's a common interface (such as getMessage()) which the exception always adheres to. That improves the ability of exception handling especially debugging and logging significantly. i.e. try { ...// Main code which calls PEAR, SOAP, Smart, external stuff and so on.... } catch (Exception $e) { print "Damn something is really wrong here\n"; print $e->getMessage(); } Andi
-- Zend Engine CVS Mailing List (http://cvs.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Sterling Hughes

22 years ago
> > The reasoning is that it allows users to do a catch-all (which otherwise > we'd add to the language syntax). It also adds cleanliness to the Exception > hierarchy and allows PHP code to interact with PHP code which isn't written > by the developer knowing that there's a common interface (such as > getMessage()) which the exception always adheres to. That improves the > ability of exception handling especially debugging and logging > significantly. >
That second part is a Throwable interface, not a base class (and Exception isn't even an ABC.)
> i.e. > > try { > ...// Main code which calls PEAR, SOAP, Smart, external stuff and > so on.... > } catch (Exception $e) { > print "Damn something is really wrong here\n"; > print $e->getMessage(); > } >
I get the concept, that's the reason Exception was added. But its meant to be a voluntary thing (I believe this has been discussed before btw), a standard class that gives users something to build upon, should they want to. I think an all-your-base-is-belonging-to-Exception is the wrong way to go. If you really want a catch-all or some type of consistency the way to go is either a Throwable interface (which makes it more of a pain to write exceptions) or the generic: catch ($e) { } syntax. _Sterling
-- "Reductionists like to take things apart. The rest of us are just trying to get it together." - Larry Wall, Programming Perl, 3rd Edition

Timm Friebe

22 years ago
On Fri, 2004-02-13 at 18:54, Sterling Hughes wrote: [...]
> I get the concept, that's the reason Exception was added. But its meant > to be a voluntary thing (I believe this has been discussed before btw), > a standard class that gives users something to build upon, should they > want to. I think an all-your-base-is-belonging-to-Exception is the > wrong way to go.
I agree with Sterling. What if I have some really methods in my base class that I rely on being existant in each and every subclass of it, including Exception (or any other name I thought of to work around "Exception" being built-in)? - Timm

Ferdinand Beyer

22 years ago
On 15 Feb 2004 at 13:08, Zeev Suraski wrote:
> At 12:04 15/02/2004, Timm Friebe wrote: > >I agree with Sterling. What if I have some really methods in my base > >class that I rely on being existant in each and every subclass of it, > >including Exception (or any other name I thought of to work
around
> >"Exception" being built-in)? > > Couldn't quite understand that. Can you elaborate on what you
mean exactly? I'm with Timm here. For example I could have a framework with a complex class hierarchy: CObject - base class for _all_ classes CException extends CObject - base class for all exceptions .... This is not possible since CException cannot extend both CObject and CException. In my opinion we should provide a throwable interface and an exception base class implementing that interface. Forthermore we should use a common prefix for the identifiers but that's a different topic.
-- Ferdinand Beyer <fb@fbeyer.com>

Zeev Suraski

22 years ago
At 12:04 15/02/2004, Timm Friebe wrote:
>I agree with Sterling. What if I have some really methods in my base >class that I rely on being existant in each and every subclass of it, >including Exception (or any other name I thought of to work around >"Exception" being built-in)?
Couldn't quite understand that. Can you elaborate on what you mean exactly? Zeev

Timm Friebe

22 years ago
On Sun, 2004-02-15 at 12:08, Zeev Suraski wrote:
> At 12:04 15/02/2004, Timm Friebe wrote: > >I agree with Sterling. What if I have some really methods in my base > >class that I rely on being existant in each and every subclass of it, > >including Exception (or any other name I thought of to work around > >"Exception" being built-in)? > > Couldn't quite understand that. Can you elaborate on what you mean exactly?
Sure: Assume, in my current setup, I have my own exception class, which extends my own base class, called Object. The class Object has a method getClass() which returns the Reflection_Class for $this ( there are actually some more methods in it that are available to all extending classes). Example, shortened for brevity: <?php class Object { public function getClass() { return new Reflection_Class($this); } } class _Exception extends Object { } $e= new _Exception(); var_dump($e->getClass()->getName()); ?> In all of my code, I rely on each and every object having this method, which of course will be broken for any exception I will now need to extend from the built-in exception class (that does not have this method). Of course, I could always extend the built-in exception and add the base class' methods to it, too, resulting in duplicate code and not solving the problem for Exception itself. Without the requirement to extend the built-in exception class, I could get around this by simply not using it and for those cases where it might occur, catching it and rethrowing my own exception. As of B4, this is no longer possible. That's why i was agreeing to Sterling in saying it should be optional to use the built-in exception class. If there was a requirement to implement an interface (call it Throwable, for instance), simply let the built-in class implement it. People wouldn't have to get into interfaces when using (and/or subclassing) it but *only* for the case when they want something similar to what I described above. People wanting this will tend to be the kind of people that know about interfaces, anyway:) - Timm

Cristiano Duarte

22 years ago
Hi Timm, On Sun, 15 Feb 2004 12:53:21 +0100, Timm Friebe wrote:
> As of B4, this is no longer possible. That's why i was agreeing to > Sterling in saying it should be optional to use the built-in exception > class. If there was a requirement to implement an interface (call it > Throwable, for instance), simply let the built-in class implement it. > People wouldn't have to get into interfaces when using (and/or > subclassing) it but *only* for the case when they want something > similar to what I described above. People wanting this will tend to be > the kind of people that know about interfaces, anyway:)
First of all, I think there must be a "catch all" method for exceptions. This can be implemented by forcing a "base class", using an "interface" or a language construct. IMHO, as you said, using an interface and letting the built-in class implement it is the best approach. But only instances of classes wich implement this interface should be throw or caught(language enforcement). With this enforcement, we can have a "catch all" for exceptions with less pain. Cristiano Duarte

Timm Friebe

22 years ago
On Sun, 2004-02-15 at 16:09, Cristiano Duarte wrote:
> Hi Timm,
[...]
> IMHO, as you said, using an interface and letting the built-in class > implement it is the best approach. But only instances of classes wich > implement this interface should be throw or caught(language enforcement). > With this enforcement, we can have a "catch all" for exceptions with > less pain.
... and more flexibility for users like me who have their very own ideas about a lot of thins:) The following patch includes: * An interface called "Throwable" which is implemented by the built-in exception class. The interface is defined as following: interface Throwable { function getMessage(); function getFile(); function getLine(); } * Checks on whether the exception thrown implements this interface (rather than checking on subclasses of Exception), therefore keeping the status quo of having a language enforcement on what one can throw and "being clean" (which were the arguments for this base class in the beginning, right?). * The necessary changes to zend_catch_handler() which would only check subclassing. Catch-all is implemented in the following way: try { // [...] } catch (Throwable $e) { print $e; } * A \n at the end of Exception::__toString() which does not require one to write echo $e->__toString(), "\n" all the time. Marcus, I do not think this adds any complexity. Especially not for the user you are describing as "the average" and "wanting an easy exception model" "the PHP way" "without any knowledge of interfaces":) For them, this change is completely transparent (no changes need to be made). In turn, it will make me and a couple of other people happy by leaving us the freedom to decide whether we want (as Sterling put it) all-your-base-our-belong-to-us-exceptions or design our own (and then live with the fact that we can only accomplish 99% of the built-in-exception's functionality). - Timm

Andi Gutmans

22 years ago
Hey, Marcus didn't mean it adds complexity to the code but to PHP. It's obviously quite easy to implement this interface; implementation was never a problem. I don't really care too much if we have such an interface or not, although I do think that it just makes things complex and I doubt almost anyone will have a need for it. I think the arguments given on this list for why we need this interface were mainly academic and an attempt of people familiar with Java to copy the hierarchy. The actual times you will need such an interface is quite rare and I don't think it's worth the complexity for the one in a million purist guy (i.e. people who want all their classes to inherit from a CObject including exceptions). Andi P.S. - BTW, why not call it IException (or ExceptionInterface) instead of Throwable? I think for people who don't know Java, it makes more sense. At 07:26 PM 2/15/2004 +0100, Timm Friebe wrote:

Hans Lellelid

22 years ago
Andi Gutmans wrote:
> Hey, > > Marcus didn't mean it adds complexity to the code but to PHP. It's > obviously quite easy to implement this interface; implementation was > never a problem. > I don't really care too much if we have such an interface or not, > although I do think that it just makes things complex and I doubt almost > anyone will have a need for it.
Personally as PHP developer (as opposed to internals developer) I am not in favor of having an interface, because I want to know that try { // ... } catch (Exception $e) { // ... } will catch *all* exceptions thrown by any libraries I choose to use, etc. Mixing the interface means requiring PHP developers to catch() on the interface everywhere or risk having uncaught exceptions when a 3rd party package they are using decides to throw IException implementing classes instead. Maybe telling people (developers) to use the IException everywhere is ok, but is not what people are expecting right now. Hans

Adam Bregenzer

22 years ago
On Mon, 2004-02-16 at 08:39, Hans Lellelid wrote:
> will catch *all* exceptions thrown by any libraries I choose to use, > etc. Mixing the interface means requiring PHP developers to catch() on > the interface everywhere or risk having uncaught exceptions when a 3rd > party package they are using decides to throw IException implementing > classes instead. Maybe telling people (developers) to use the > IException everywhere is ok, but is not what people are expecting right now.
My biggest motivation for not having an exception class was to prevent people from having a catch all with exceptions. Personally, I think that attitude is what has caused an over use of exceptions (making every function throw Exception so as to not have to deal with them) as well as let people use code without understanding exceptions (throwing a catch all around an API call so they don't have to really handle any exceptions). I would like to be able to throw exceptions that must be caught explicitly to help deter people from just ignoring them. It seems however that I am in the vast minority. I understand the simplicity argument and think it is appropriate for PHP given it's user base. In fact I am now wondering if exceptions aren't a potential trap that will cause more problems than benefits. I like that PHP != Java. So, how about prototype inheritance? (J.K.!) Regards, Adam
-- Adam Bregenzer adam@bregenzer.net http://adam.bregenzer.net/

Hans Lellelid

22 years ago
Hi Adam - Adam Bregenzer wrote:
>My biggest motivation for not having an exception class was to prevent >people from having a catch all with exceptions. Personally, I think >that attitude is what has caused an over use of exceptions (making every >function throw Exception so as to not have to deal with them) as well as >let people use code without understanding exceptions (throwing a catch >all around an API call so they don't have to really handle any >exceptions). I would like to be able to throw exceptions that must be >caught explicitly to help deter people from just ignoring them. It >seems however that I am in the vast minority. >
I agree with the basic premise the you want people to actually think about the Exceptions they are catching. In general I think apps should have their own exceptions and throw only Exceptions derived from those; in practice, I'm sure there will be lots of little apps that don't really need their own Exception tree and so it's nice to have a base Exception class. I don't agree, though, with the idea that if I don't know that your application throws YourException that it should by default leak through my error handling & come out as a PHP fatal error! Perhaps we're thinking of different scenarios for this stuff. I'm thinking of examples where I have a framework or system that may include 3rd party components to do work. For example, Phing (PHP5 Ant port) can use a number of PEAR packages or user-defined classes in its buildfiles. It would not be appropriate for any of those pieces of code to terminate the build by throwing an Exception that Phing doesn't expect (catch). At Phing task is an isolated activity and if a package that is used by a task throws any Throwable, it needs to be caught by the Phing task and logged so that the build script can continue (or abort, if the user has specified that behavior). This isn't really an argument against using an interface, of course, but I definitely don't think it'd be good to build a system that was designed to get around catch() blocks. In development such a system might be helpful, but in production I think it would be a nightmare. Hans

Adam Bregenzer

22 years ago
On Tue, 2004-02-17 at 00:24, Hans Lellelid wrote:
> I agree with the basic premise the you want people to actually think > about the Exceptions they are catching. In general I think apps should > have their own exceptions and throw only Exceptions derived from those; > in practice, I'm sure there will be lots of little apps that don't > really need their own Exception tree and so it's nice to have a base > Exception class. I don't agree, though, with the idea that if I don't > know that your application throws YourException that it should by > default leak through my error handling & come out as a PHP fatal error! > Perhaps we're thinking of different scenarios for this stuff. I'm > thinking of examples where I have a framework or system that may include > 3rd party components to do work. For example, Phing (PHP5 Ant port) can > use a number of PEAR packages or user-defined classes in its > buildfiles. It would not be appropriate for any of those pieces of code > to terminate the build by throwing an Exception that Phing doesn't > expect (catch). At Phing task is an isolated activity and if a package > that is used by a task throws any Throwable, it needs to be caught by > the Phing task and logged so that the build script can continue (or > abort, if the user has specified that behavior).
If I understand correctly, PHP 5 uses an unchecked exception implementation (functions are not required to declare what exceptions they throw). I very much agree that unchecked exceptions are the preferred way to handle things, however ideally I do not think they should be the only way. I think there is value in a checked exception and that being able to define an exception that would not be generically caught by a "catch (Exception $e)" is a good thing. In fact *I* think using a catch all should generate a compiler warning. ;) Instead I think exceptions that are not specifically handled should pass up through the code and into the PHP engine. There they can be caught and the application can handle them like any other error through set_error_handler(). How is that any less useful than "catch (Exception $e) {echo $e->getMessage()}"? In fact, I think it is more useful because it more appropriately reflects the context that the error is being handled in; something has gone terribly wrong and I don't know what to do to fix it. Clearly the programmer is not handling these exceptions explicitly in their code. Additionally, the error_handler prototype can be passed the exception object so that the information is available. To me exceptions are useful for one reason: context. First of all they hold more flexibility over trigger_error(). By creating custom Exception classes (either by extending the Exception class or making a new base exception class) you can provide additional context about the error. In languages that have exceptions I never extend the default classes unless I find it necessary to do so. For example, if I can handle all my exceptions using the default classes in Java I will. I see a lot of discussion here of ways to let people use catch all statements, not handle exceptions, group exceptions into certain keyholes, etc. To me this is a bad thing and something that is done all too often with exceptions and only causes problems. Often it is a result of exceptions being used in-appropriately in the fist place. All that being said, I'll say again that I am against complicating exceptions any further in PHP. In fact the more I think about it I become convinced PHP should at least not require exceptions be used in the same way it does not force programmers to write OO code. Part of why I love PHP is its simplicity and similarity to C. I am thoroughly enjoying the OO additions to PHP and lately have been taking great advantage of it. Conversely, I don't think the majority of PHP users use or want to use classes, much less want to learn about using exceptions properly. Here are some resources a quick search turned up that might be useful in explaining my thoughts this time: General Exception stuff: http://c2.com/cgi/wiki?UseExceptionsInsteadOfErrorValues This is a great resource, some of the links off this page are also very useful. Java based resources, obvious differences should be kept in mind: http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html Exception "best practices" in Java. http://www.hutteman.com/weblog/2003/08/31-118.html A good description of the importance of using unchecked exceptions. http://www.darrenhobbs.com/archives/000411.html He has a great perspective on checked exceptions. http://www.soletta.com/categories/javaEtc/2003/08/27.html#a324 Just another perspective to ponder. :) Regards, Adam
-- Adam Bregenzer adam@bregenzer.net http://adam.bregenzer.net/

Hans Lellelid

22 years ago
Andi Gutmans wrote:
> Hey, > > Marcus didn't mean it adds complexity to the code but to PHP. It's > obviously quite easy to implement this interface; implementation was > never a problem. > I don't really care too much if we have such an interface or not, > although I do think that it just makes things complex and I doubt almost > anyone will have a need for it.
Personally as PHP developer (as opposed to internals developer) I am not in favor of having an interface, because I want to know that try { // ... } catch (Exception $e) { // ... } will catch *all* exceptions thrown by any libraries I choose to use, etc. Mixing the interface means requiring PHP developers to catch() on the interface everywhere or risk having uncaught exceptions when a 3rd party package they are using decides to throw IException implementing classes instead. Maybe telling people (developers) to use the IException everywhere is ok, but is not what people are expecting right now. Hans

Ard Biesheuvel

22 years ago
Hans Lellelid wrote:
> Personally as PHP developer (as opposed to internals developer) I am not > in favor of having an interface, because I want to know that > > try { > // ... > } catch (Exception $e) { > // ... > } > > will catch *all* exceptions thrown by any libraries I choose to use, > etc. Mixing the interface means requiring PHP developers to catch() on
Actually, you would use 'catch (IException $e)' which would catch the IException-derived Exception and all other classes that implement it.
-- Ard

Hans Lellelid

22 years ago
Hi - Ard Biesheuvel wrote:
> Hans Lellelid wrote: > >> Personally as PHP developer (as opposed to internals developer) I am >> not in favor of having an interface, because I want to know that >> >> try { >> // ... >> } catch (Exception $e) { >> // ... >> } >> >> will catch *all* exceptions thrown by any libraries I choose to use, >> etc. Mixing the interface means requiring PHP developers to catch() on > > > Actually, you would use 'catch (IException $e)' which would catch the > IException-derived Exception and all other classes that implement it. >
Right ... what I'm saying is that I don't think people are expecting to have to catch(IException ...). I guess it'd be ok to simply change the docs to instruct people to always use IException, but I do think it's more intuitive that catch(Exception) catches everything. Moreover, I agree that intentionally creating exceptions that leak shouldn't be done. If it's thrown it's meant to be caught -- IMHO. Hans

Stephane Drouard

22 years ago
== Quote from Andi Gutmans (andi@zend.com)'s article
> Marcus didn't mean it adds complexity to the code but to PHP. It's > obviously quite easy to implement this interface; implementation was never > a problem. > I don't really care too much if we have such an interface or not, although > I do think that it just makes things complex and I doubt almost anyone will > have a need for it. > I think the arguments given on this list for why we need this interface > were mainly academic and an attempt of people familiar with Java to copy > the hierarchy. The actual times you will need such an interface is quite > rare and I don't think it's worth the complexity for the one in a million > purist guy (i.e. people who want all their classes to inherit from a > CObject including exceptions).
Implementing an interface would also help in getting round the very restrictive Exception implementation: * all methods are final, including getMessage() !!!, * its trace member is private.
> P.S. - BTW, why not call it IException (or ExceptionInterface) instead of > Throwable? I think for people who don't know Java, it makes more sense.
Why not, but in that case, the other PHP interfaces should also follow this naming convention. Stephane

Marcus Börger

22 years ago
Hello Stephane, Monday, February 16, 2004, 5:13:46 PM, you wrote:
> == Quote from Andi Gutmans (andi@zend.com)'s article >> Marcus didn't mean it adds complexity to the code but to PHP. It's >> obviously quite easy to implement this interface; implementation was never >> a problem. >> I don't really care too much if we have such an interface or not, although >> I do think that it just makes things complex and I doubt almost anyone will >> have a need for it. >> I think the arguments given on this list for why we need this interface >> were mainly academic and an attempt of people familiar with Java to copy >> the hierarchy. The actual times you will need such an interface is quite >> rare and I don't think it's worth the complexity for the one in a million >> purist guy (i.e. people who want all their classes to inherit from a >> CObject including exceptions).
> Implementing an interface would also help in getting round the very > restrictive Exception implementation: > * all methods are final, including getMessage() !!!, > * its trace member is private.
as i said before there is a reason for that: I played a long time with exceptions until they became what they are right now. And and attempt to increase the visibility of one of its members can be used to make it SEGV. So i don't want more visibility. Also where is the reason? You can read everything just fine and you can overload you exception to print out better formatted output and whatever. The only place where you need to change such member in derived classes is when you are using exceptions as flow control. And duing so is violating exception rule number two. So don't expect this to be changed.
>> P.S. - BTW, why not call it IException (or ExceptionInterface) instead of >> Throwable? I think for people who don't know Java, it makes more sense.
> Why not, but in that case, the other PHP interfaces should also follow this naming convention.
> Stephane
-- Best regards, Marcus mailto:helly@php.net

Ard Biesheuvel

22 years ago
Marcus Boerger wrote:
> as i said before there is a reason for that: I played a long time with > exceptions until they became what they are right now. And and attempt > to increase the visibility of one of its members can be used to make it > SEGV. So i don't want more visibility. Also where is the reason? You can
Correct me if I'm wrong, but are you saying that the concept of extendable Exception methods in general was rejected because its current implementation segfaults ? That feels kind of backwards to me ...
> read everything just fine and you can overload you exception to print out > better formatted output and whatever. The only place where you need to > change such member in derived classes is when you are using exceptions > as flow control. And duing so is violating exception rule number two. So > don't expect this to be changed.
So we're back to try {} catch (MyException $e) { do_something_with($e->myGetMessage()); } catch (Exception $e) { do_something_with($e->getMessage()); } which totally defeats the purpose of subclassing Exception in the first place. This has nothing to do 'violating the 10 commandments of exception'. Couldn't you replace this with a non-final implementation that calls a private (== final in this case) method in the default implementation ?
-- Ard

Marcus Börger

22 years ago
Hello Ard, Monday, February 16, 2004, 9:51:51 PM, you wrote:
> Marcus Boerger wrote:
>> as i said before there is a reason for that: I played a long time with >> exceptions until they became what they are right now. And and attempt >> to increase the visibility of one of its members can be used to make it >> SEGV. So i don't want more visibility. Also where is the reason? You can
> Correct me if I'm wrong, but are you saying that the concept of > extendable Exception methods in general was rejected because its current > implementation segfaults ? That feels kind of backwards to me ...
You are wrong. The point is i am not willing to risc unstabilites with exceptions. This is a special class that heavily interacts with the executor and facilities used even after exceution hence i must be sure several intenal properties are in an exact and intact form at 100%.
>> read everything just fine and you can overload you exception to print out >> better formatted output and whatever. The only place where you need to >> change such member in derived classes is when you are using exceptions >> as flow control. And duing so is violating exception rule number two. So >> don't expect this to be changed.
> So we're back to
> try {} > catch (MyException $e) { > do_something_with($e->myGetMessage()); > } > catch (Exception $e) { > do_something_with($e->getMessage()); > }
> which totally defeats the purpose of subclassing Exception in the first > place. This has nothing to do 'violating the 10 commandments of exception'. > Couldn't you replace this with a non-final implementation that calls a > private (== final in this case) method in the default implementation ?
No those are read access members to private property members. When you lok at the exception class: php -r 'reflection_class::export("exception");' then you'll encounter that you can overload __toString() and the __construct(). Or in other words you should use 'print $e' or '(string)$e' or '$e->__toString()'.
-- Best regards, Marcus mailto:helly@php.net

Stephane Drouard

22 years ago
== Quote from Marcus Boerger (helly@php.net)'s article
> as i said before there is a reason for that: I played a long time with > exceptions until they became what they are right now. And and attempt > to increase the visibility of one of its members can be used to make it > SEGV. So i don't want more visibility. Also where is the reason? You can > read everything just fine and you can overload you exception to print out > better formatted output and whatever. The only place where you need to > change such member in derived classes is when you are using exceptions > as flow control. And duing so is violating exception rule number two. So > don't expect this to be changed.
Before B4, I had my own exception base class with all the features implemented within the PHP's Exception (stack dump, ...), but without any limitation. I also remember that someone sent a "99%" equivalent of the Exception class. So the interface would certainly be the best for everybody. Exception class for many people, IException (or whatever the name) for people that want more flexibility. Compared with Timm's patch, I would also have a getTrace() method, to allow PHP to dump the stack. For sure, a "catch all" will be now implemented as catch(IException $e)... Stephane

Timm Friebe

22 years ago
On Mon, 2004-02-16 at 09:35, Andi Gutmans wrote:
> Hey, > > Marcus didn't mean it adds complexity to the code but to PHP.
I can't see how it would: For those relying on the built-in base class, it won't change a single thing. For those wanting their own exception (or to be more correct: _class_) hierarchy (me, for example, or Ferdinand, or - if I understood him correctly - Sterling, which makes three and is therefore more than "one in a million" you mentioned:)) it opens up possibilities and adds flexibility to the language. Flexibility is a point in which PHP has always been very good: No enforcements on types, classes, solutions. Everyone is welcome to and is actually creating amazing frameworks (PEAR, binary cloud, Horde, to name a few of the big ones) _ontop_ of the core of PHP / the Zend Engine.
> I think the arguments given on this list for why we need this interface > were mainly academic
Hrm, so my argument about Object::getClass() was academic? I actually never finished my degree:)
> and an attempt of people familiar with Java to copy > the hierarchy.
A lot of people have base classes and let all of their other classes extend them. I don't think this is specifically related to Java. Of course, I know how to work around this - by duplicating code into subclasses of exceptions, by simply having a global function or writing an extension which gets rid of the exception class after Engine startup, but wouldn't these solutions be rather "unclean" and wasn't your argument for this that it is a "clean" solution? Look at it the other way around: Would anybody be investing such an amount of time into arguing (which, ATM, I am) *if* we had the interface solution?
> The actual times you will need such an interface is quite > rare and I don't think it's worth the complexity for the one in a million > purist guy (i.e. people who want all their classes to inherit from a > CObject including exceptions).
Again, I don't see any complexity arising from this: The average user would simply use "catch (IException $e)" instead of "catch (Exception $e)" and have what he/she wants: All exceptions are being caught. The "purist guy" (me, in this case) would use the same semantics *and* be able to have all of the purist and academic stuff he wants:)
> Andi > > P.S. - BTW, why not call it IException (or ExceptionInterface) instead of > Throwable? I think for people who don't know Java, it makes more sense.
Agreed. An updated patch is attached. - Timm

Steven D. Nowicki

22 years ago
Timm Friebe wrote:
>>Andi >> >>P.S. - BTW, why not call it IException (or ExceptionInterface) instead of >>Throwable? I think for people who don't know Java, it makes more sense. > > > Agreed. An updated patch is attached. > > - Timm >
I think if you're going to rename Throwable to IException, the naming scheme for the other built-in interfaces should be consistent. Traversable, Iterator, IteratorAggregate, and ArrayAccess should be renamed ITraversable, IIterator, IIteratorAggregate, and IArrayAccess. Same should apply to any other built-ins that I'm forgetting. - Steve

Andi Gutmans

22 years ago
At 10:35 PM 2/16/2004 +0100, Timm Friebe wrote:
>On Mon, 2004-02-16 at 09:35, Andi Gutmans wrote: > > Hey, > > > > Marcus didn't mean it adds complexity to the code but to PHP. > >I can't see how it would: For those relying on the built-in base class, >it won't change a single thing. > >For those wanting their own exception (or to be more correct: _class_) >hierarchy (me, for example, or Ferdinand, or - if I understood him >correctly - Sterling, which makes three and is therefore more than "one >in a million" you mentioned:)) it opens up possibilities and adds >flexibility to the language.
Don't take internals@ and their profile as a statistical equal to the PHP community.
>Flexibility is a point in which PHP has always been very good: No >enforcements on types, classes, solutions. Everyone is welcome to and is >actually creating amazing frameworks (PEAR, binary cloud, Horde, to name >a few of the big ones) _ontop_ of the core of PHP / the Zend Engine. > > > I think the arguments given on this list for why we need this interface > > were mainly academic > >Hrm, so my argument about Object::getClass() was academic? I actually >never finished my degree:) > > > and an attempt of people familiar with Java to copy > > the hierarchy. > >A lot of people have base classes and let all of their other classes >extend them. I don't think this is specifically related to Java.
I wouldn't say "a lot". In most code I have seen this doesn't happen. Yes, I have seen very small amount of places where it does, and in that case, they didn't have exceptions and I don't think that in all situations having the exceptions inherit that class is important.
>Of course, I know how to work around this - by duplicating code into >subclasses of exceptions, by simply having a global function or writing >an extension which gets rid of the exception class after Engine startup, >but wouldn't these solutions be rather "unclean" and wasn't your >argument for this that it is a "clean" solution? > >Look at it the other way around: Would anybody be investing such an >amount of time into arguing (which, ATM, I am) *if* we had the interface >solution? > > > The actual times you will need such an interface is quite > > rare and I don't think it's worth the complexity for the one in a million > > purist guy (i.e. people who want all their classes to inherit from a > > CObject including exceptions). > >Again, I don't see any complexity arising from this: The average user >would simply use "catch (IException $e)" instead of "catch (Exception >$e)" and have what he/she wants: All exceptions are being caught. > >The "purist guy" (me, in this case) would use the same semantics *and* >be able to have all of the purist and academic stuff he wants:)
But that's exactly it. PHP is not for the purist and academic guy like you. We don't try and please people like you :) We want to keep PHP accessible and easy to use for the masses and adding an additional layer complicates things for the end user. You are more advanced than the average PHP developer as you are writing C code for the PHP core :) Look, I'm not very strongly against this interface but you (and some others here) have to understand that you are not the average PHP user and PHP has never been targeted at the academy. There are plenty of languages to take that spot such as LISP, ML, Java, Prolog, Smalltalk and so on... Sometimes being not quite 100% pure makes the language easier to use and to understand. Andi

Stanislav Malyshev

22 years ago
>> >Again, I don't see any complexity arising from this: The average user >> >would simply use "catch (IException $e)" instead of "catch (Exception
That looks weird. Why IException? Ah, because it's an interface. And what's an interface? And why should I know about interfaces if I just want to catch damn exceptions and that's all? Simple stuff should be simple. If you want to catch exception, you shouldn't go and learn how interfaces work in PHP and what are the inheritance rules and ton of other stuff. You should just do catch(Exception $e) and that's it.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109

Derick Rethans

22 years ago
On Tue, 17 Feb 2004, Stanislav Malyshev wrote:
> >> >Again, I don't see any complexity arising from this: The average user > >> >would simply use "catch (IException $e)" instead of "catch (Exception > > That looks weird. Why IException? Ah, because it's an interface. And > what's an interface? And why should I know about interfaces if > I just want to catch damn exceptions and that's all? > > Simple stuff should be simple. If you want to catch exception, you > shouldn't go and learn how interfaces work in PHP and what are the > inheritance rules and ton of other stuff. You should just do > catch(Exception $e) and that's it.
Right, can't agree more with this. Derick

Stephane Drouard

22 years ago
== Quote from Derick Rethans (derick@php.net)'s article
> On Tue, 17 Feb 2004, Stanislav Malyshev wrote: > > > >> >Again, I don't see any complexity arising from this: The average user > > >> >would simply use "catch (IException $e)" instead of "catch (Exception > > > > That looks weird. Why IException? Ah, because it's an interface. And > > what's an interface? And why should I know about interfaces if > > I just want to catch damn exceptions and that's all? > > > > Simple stuff should be simple. If you want to catch exception, you > > shouldn't go and learn how interfaces work in PHP and what are the > > inheritance rules and ton of other stuff. You should just do > > catch(Exception $e) and that's it. > > Right, can't agree more with this. > > Derick
The problem is not the name, but the fact that some people would like to have an interface as the exception base hierarchy. "Throwable" was first proposed, but some people considered it was too Java oriented. We could also have this interface named "Exception" and the PHP class implementation "PhpException" .... Personally I don't like interfaces start with an 'I'. I would also prefer "Error" instead of "Exception" because I consider what we get is an error, exception is just the mechanism to report errors. Stephane

Andi Gutmans

22 years ago
At 04:13 PM 2/16/2004 +0000, Stephane Drouard wrote:
> > P.S. - BTW, why not call it IException (or ExceptionInterface) instead of > > Throwable? I think for people who don't know Java, it makes more sense. > >Why not, but in that case, the other PHP interfaces should also follow >this naming convention.
Yeah that might be a good idea and make things clearer, i.e., IArrayAccess and so on. Andi