Last active
August 29, 2015 14:25
-
-
Save wgkoro/64007868742bb69fad4f to your computer and use it in GitHub Desktop.
try{ }catch の中でファイル書き込みを実行し、例外なげたらどうなるんだっけ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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