gh7875.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. GH-7875 (mails are sent even if failure to log throws exception)
  3. --SKIPIF--
  4. <?php
  5. $filename = __DIR__ . "/gh7875.mail.log";
  6. touch($filename);
  7. chmod($filename, 0444);
  8. clearstatcache();
  9. $is_writable = is_writable($filename);
  10. chmod($filename, 0644);
  11. unlink($filename);
  12. if ($is_writable) die("skip cannot make file read-only");
  13. ?>
  14. --INI--
  15. sendmail_path={MAIL:{PWD}/gh7875.mail.out}
  16. mail.log={PWD}/gh7875.mail.log
  17. --FILE--
  18. <?php
  19. function exception_error_handler($severity, $message, $file, $line) {
  20. if (!(error_reporting() & $severity)) {
  21. return;
  22. }
  23. throw new ErrorException($message, 0, $severity, $file, $line);
  24. }
  25. set_error_handler("exception_error_handler");
  26. touch(__DIR__ . "/gh7875.mail.log");
  27. chmod(__DIR__ . "/gh7875.mail.log", 0444);
  28. try {
  29. mail('recipient@example.com', 'Subject', 'Body', []);
  30. echo 'Not Reached';
  31. } catch (\Exception $e) {
  32. echo $e->getMessage(), PHP_EOL;
  33. var_dump(file_exists(__DIR__ . "/gh7875.mail.out"));
  34. }
  35. ?>
  36. --CLEAN--
  37. <?php
  38. @chmod(__DIR__ . "/gh7875.mail.log", 0644);
  39. @unlink(__DIR__ . "/gh7875.mail.log");
  40. @unlink(__DIR__ . "/gh7875.mail.out");
  41. ?>
  42. --EXPECTF--
  43. mail(%s): Failed to open stream: Permission denied
  44. bool(false)