As i explained there is no good other way to tell the user the ctor has failed. The two ways out out are:
Personally I'd much prefer a way of returning a value from a constructor, i.e. to be able to 'return null;' or a similar language construct so I could do 'if ($db = new SQLiteDatabase)'
It would also mean that I would run into a 'calling method on a non-object' error if I don't check it (which is fine).
I strongly believe that we are talking about some basic initialization stuff to be done at the beginning of an application like creating a DB connection and setting up some environment only. Otherwise you'd imply that you start try/catching on every object instantation which is definitely not the way to go!
Alternatively (something which works for PHP4 already) one could simply have a status a la
$db = new SQLiteDatabase;
if ($db->isValid)
which is less elegant but based on the assumption that it has to be done at most 10 times in an application works just as well.
In my opinion exceptions-for-ctor-failure is already a work-around abusing exceptions in an at least arguable way. You _require_ users to learn about a whole new (and complicated) paradigm in error handling which I'd very much avoid.
Hey if you want to work with OO then deal with all OO issues or create ugly workarounds and don't pretend the language is OO at
OO works very well without exceptions. Exceptions has to do with error handling, not with data encapsulation (which OO is about).
Yes, I like OO. No I don't like exceptions. And I worked with both.
- Chris
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php