ID: 32100
Updated by: [EMAIL PROTECTED]
Reported By: ceefour at gauldong dot net
Status: Open
Bug Type: Feature/Change Request
-Operating System: All
+Operating System: *
PHP Version: 5.0.3
New Comment:
We've had long discussions and came to the only conclusion that we
don't need that, for more search the mailing list archieves.
Besides the following is absolutley equivalent:
mysql_query("LOCK TABLES mytable WRITE");
try {
// ... do lots of queries here
} catch (Exception $e) {
// do nothing here
}
mysql_query("UNLOCK TABLES");
The only difference is the second example does rethrow the exception.
Though this is still possible (however much more to type) it is wrong
design. Since obviously you are using the exceptions as control flow.
And that design looks like Java where it unlike with PHP makes somewhat
sense.
Previous Comments:
------------------------------------------------------------------------
[2005-02-25 07:07:44] ceefour at gauldong dot net
Description:
------------
PHP 5 has specifically decided not to support 'finally'. Why?
This is one of numerous cases why finally is useful:
mysql_query("LOCK TABLES mytable WRITE");
try {
// ... do lots of queries here
} finally {
mysql_query("UNLOCK TABLES");
}
You need to use UNLOCK TABLES otherwise your tables won't get unlocked
when an exception is thrown. This is especially bad if you use
persistent connections.
It is possible to emulate finally using try/catch but this introduces
code redundancy and may create inconsistent code:
mysql_query("LOCK TABLES mytable WRITE");
try {
// ... do lots of queries here
mysql_query("UNLOCK TABLES");
} catch(Exception $e) {
mysql_query("UNLOCK TABLES");
throw $e;
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32100&edit=1