Skip to content

Instantly share code, notes, and snippets.

@wgkoro
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgkoro/64007868742bb69fad4f to your computer and use it in GitHub Desktop.
Save wgkoro/64007868742bb69fad4f to your computer and use it in GitHub Desktop.
try{ }catch の中でファイル書き込みを実行し、例外なげたらどうなるんだっけ?
<?php
// 結果:例外なげてもファイルに書き込まれる
try {
$fp = fopen('./fugafuga.log', 'a');
fwrite($fp, '123');
fclose($fp);
throw new Exception('e');
}
catch(Exception $e) {
echo 'hogehoge' .$e->getMessage();
}
// fcloseの前に例外なげても書き込まれる。ただ、ファイルロックされっぱなしになりそうだが・・・
try {
$fp = fopen('./uryyyyyy.log', 'a');
fwrite($fp, '123');
throw new Exception('e');
fclose($fp);
}
catch(Exception $e) {
echo 'hogehoge' .$e->getMessage();
}
// 結果:同上。書き込まれる。
try {
error_log('abc', 3, './hogehoge.log');
throw new Exception('e');
}
catch(Exception $e) {
echo 'hogehoge' .$e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment