Skip to content

Commit 2f128ab

Browse files
committed
Use try/finally to restore error handlers
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 631a6ae commit 2f128ab

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

File/File.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ public function move(string $directory, string $name = null)
9393
$target = $this->getTargetFile($directory, $name);
9494

9595
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
96-
$renamed = rename($this->getPathname(), $target);
97-
restore_error_handler();
96+
try {
97+
$renamed = rename($this->getPathname(), $target);
98+
} finally {
99+
restore_error_handler();
100+
}
98101
if (!$renamed) {
99102
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
100103
}

File/UploadedFile.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ public function move(string $directory, string $name = null)
182182
$target = $this->getTargetFile($directory, $name);
183183

184184
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
185-
$moved = move_uploaded_file($this->getPathname(), $target);
186-
restore_error_handler();
185+
try {
186+
$moved = move_uploaded_file($this->getPathname(), $target);
187+
} finally {
188+
restore_error_handler();
189+
}
187190
if (!$moved) {
188191
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
189192
}

0 commit comments

Comments
 (0)