How can I get around the lack of a finally block i

2019-01-17 09:34发布

PHP prior to version 5.5 has no finally block - i.e., whereas in most sensible languages, you can do:

try {
   //do something
} catch(Exception ex) {
   //handle an error
} finally {
   //clean up after yourself
}

PHP has no notion of a finally block.

Anyone have experience of solutions to this rather irritating hole in the language?

7条回答
Deceive 欺骗
2楼-- · 2019-01-17 10:06

If anyone is still keeping track of this question, you might be interested in checking out the (brand new) RFC for a finally language feature in the PHP wiki. The author already seems to have working patches, and I'm sure the proposal would benefit from other developers' feedback.

查看更多
登录 后发表回答