Re: base class
| From: | Stephane Drouard | Date: | Sat, 24 Jan 2004 15:20:33 +0000 |
| Subject: | Re: base class | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7313@lists.php.net to get a copy of this message | ||
== Quote from Timm Friebe (thekid@thekid.de)'s article
> It's basically the same with the built-in exception class. I can't have
> my own (at least not with the sexy-most name "Exception"). Then, in my
> (very personal) view I want it designed differently, and want to have it
> extend _my_ base class (which, incidentally, is called "Object" and does
> _not_ have constructor:)) - again, this is _my_ very personal feeling
> about how it should be - so I'll just have my own exception, which is
> perfectly OK and dealt with very well by the Zend Engine.
Exception is a very good example why I think sharing a common base class is necessary (I also posted
a message on that). Imagine I use my own exception base class, and you use your own.
Now what will happen if I get some code from you? I will have to review all my code and verify
everywhere I want to catch all the exceptions (kind of "finally" clause), if one of your
exception classes could be thrown and then add your base class in the catch list. Not so easy and
prone to bugs.
To avoid that, either PHP should implement a generic catch (like C++ "catch(...)" or
"finally") or we have to share the same base class, which could be empty or be an
interface.
Many OO languages impose base classes and, for sure, they can not implement all everybody needs, and
may sometimes be contradictory with your expectation, but this is a constraint we should accept to
simplify programming and particularly code sharing.
Regards,
Stephane