diff --git a/src/error/PhutilErrorTrap.php b/src/error/PhutilErrorTrap.php index e6614ad..94d291d 100644 --- a/src/error/PhutilErrorTrap.php +++ b/src/error/PhutilErrorTrap.php @@ -1,82 +1,83 @@ getErrorsAsString(); * $trap->destroy(); * * if (!$res) { * throw new Exception('proc_open() failed: '.$err); * } * - * NOTE: You must explicitly destroy traps because they register themselves with - * @{class:PhutilErrorHandler}, and thus will not be destroyed when `unset()`. + * IMPORTANT: You must explicitly destroy traps because they register + * themselves with @{class:PhutilErrorHandler}, and thus will not be destroyed + * when `unset()`. * * Some notes on traps: * * - Traps catch all errors, including those silenced by `@`. * - Traps do not prevent errors from reaching other standard handlers. You * can use `@` to keep errors out of the logs while still trapping them. - * - Traps capture all errors until they are destroyed, usually by leaving - * scope. This means that you should not create long-lived traps, or they - * may consume unbounded amounts of memory to hold the error log. + * - Traps capture all errors until they are explicitly destroyed. This means + * that you should not create long-lived traps, or they may consume + * unbounded amounts of memory to hold the error log. */ final class PhutilErrorTrap extends Phobject { private $destroyed; private $errors = array(); public function addError($num, $str, $file, $line, $ctx) { $this->errors[] = array( 'num' => $num, 'str' => $str, 'file' => $file, 'line' => $line, 'ctx' => $ctx, ); return $this; } public function getErrorsAsString() { $out = array(); foreach ($this->errors as $error) { $out[] = $error['str']; } return implode("\n", $out); } public function destroy() { if (!$this->destroyed) { PhutilErrorHandler::removeErrorTrap($this); $this->errors = array(); $this->destroyed = true; } } public function getTrapKey() { return spl_object_hash($this); } public function __construct() { PhutilErrorHandler::addErrorTrap($this); } public function __toString() { return $this->getErrorsAsString(); } }