On 10/24/2013 06:41 PM, Nikita Popov wrote:
Hi internals!
I'd like to propose an RFC, which allows the use of exceptions within the
engine and also allows changing existing fatal errors to exceptions:
https://wiki.php.net/rfc/engine_exceptions
This topic has been cropping up in the discussions for several of the
recent RFCs and I think the time has come to consider moving away from
fatal errors.
Thoughts?
Thanks,
Nikita
Delicious, obviously ...
I will add that; if we are going to push forward with using exceptions
properly, then there's internal code throwing base Exceptions objects
and that needs to be fixed, catch(Exception $ex) will have _even less
meaning_ than it does today if we are to throw exceptions in place of
fatal errors.
I have to ask the question; why stop at half way ??
A warning does absolutely nothing for the programmer, or their code, all
it does is warn the client, who isn't very likely to even be in contact
with the programmer, even less likely has access to their code.
Take the following code:
$handle = fopen("/path/to/file", "w+");
if ($handle) {
}
If there is no $handle, I have no idea why, god only knows what the
logic looks like to detect why the failure occurred, and it doesn't have
to be fopen, can be almost anything that doesn't throw exceptions.
So, even though, some previously called function or method almost
certainly has some information that is useful, I have to make more sys
or library calls to determine the nature of the error and the code path
to take.
try {
$handle = fopen ("/path/to/file", "w+");
} catch (FileNotFoundException $fnf) {
} catch (PermissionException $pex) {
} catch (DiskFullException $dfe) {
}
[Note: the names of the exceptions and functions used _do not matter_,
consider the pattern only]
This solution has existed for years, why do we shy away from it so much
?? I've never heard a really good argument for the existence of warnings
or notices at all.
This is all said with the knowledge that some errors are truly fatal,
there is no point to, or chance of, throwing an exception.
+1 on the whole idea, however far we are able to take it ... the further
the better in my opinion ...
Cheers
Joe
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php