From c3dff4e39dcce1eab808bab4a3532828ff4d28c5 Mon Sep 17 00:00:00 2001 From: William Bruns Date: Tue, 13 Oct 2026 22:01:08 +0000 Subject: [PATCH] Remove unnecessary backslash in \DivisionByZeroError , and 2 rare instances of mixed \Exception and Exception in the finally documentation (fully qualified name used unnecessarily in an example without namespaces) Continues the change made for the match documentation at https://github.com/php/doc-en/pull/5928/changes/957f7af8d6df42e19b934ed054afa8e3dfea49aa for the finally documentation. In https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Throwable%20error%20handling%20with%20a%20finally%20block there were two instances of "\DivisionByZeroError" ) e.g. https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=\DivisionByZeroError inconsistent with the use of MOST of the "Exception" usage on the page, e.g. Example # 2, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=All%20finally%20blocks%20will%20be%20executed , Example # 3, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#3 , Example # 4, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#4 , Example # 5, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#5 , Example # 9, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#9 . There were also three "\Exception" usages inconsistent with the others (unnecessary and again before namespaces are introduced so could confuse readers), where there are inner and outer Exception catch blocks and the inner catch is using "\Exception", but such a construction does not require this. E.g. Example 6 has two instances of `catch (Exception $e)` in the same example, both referring to the same class but one using the fully qualified and one not: https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#6 >``` > function generate() > { > try { > yield 1; > yield 2; > } catch (\Exception $e) { > echo 'catch'; > } finally { > echo "finally\n"; > } >} > >try { > foreach (generate() as $i) { > echo , "\n"; > throw new Exception(); > } >} catch (Exception $e) { > echo 'outer catch'; >} >``` In the above the "outer catch" uses "Exception" and the "inner catch" uses "\Exception" but the outer/inner function scope distinction here does not require switching to the fully qualified name. The same confusion repeats in Example #7, https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Example%20#7 . and one more time in "Edge case of calling exit() in a foreach over a generator" https://web.archive.org/web/20261013211124/https://www.php.net/manual/en/control-structures.finally.php#:~:text=Edge%20case%20of%20calling%20exit()%20in%20a%20foreach%20over%20a%20generator . This commit standardizes the usage on this page and avoids possible confusion for readers as namespaces and the fully qualified name notation has not been discussed yet at this point in the documentation. (No AI or LLM assistance was used in finding this nor in preparing the commit/PR.) --- language/control-structures/finally.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/language/control-structures/finally.xml b/language/control-structures/finally.xml index 2088002f1d00..5b3b4dd450a4 100644 --- a/language/control-structures/finally.xml +++ b/language/control-structures/finally.xml @@ -24,7 +24,7 @@ function inverse($x) { try { echo inverse(5) . "\n"; -} catch (\DivisionByZeroError $e) { +} catch (DivisionByZeroError $e) { echo 'Caught error: ', $e->getMessage(), "\n"; } finally { echo "First finally.\n"; @@ -32,7 +32,7 @@ try { try { echo inverse(0) . "\n"; -} catch (\DivisionByZeroError $e) { +} catch (DivisionByZeroError $e) { echo 'Caught error: ', $e->getMessage(), "\n"; } finally { echo "Second finally.\n"; @@ -243,7 +243,7 @@ function generate() try { yield 1; yield 2; - } catch (\Exception $e) { + } catch (Exception $e) { echo 'catch'; } finally { echo "finally\n"; @@ -289,7 +289,7 @@ function generate() try { yield 1; yield 2; - } catch (\Exception $e) { + } catch (Exception $e) { echo 'catch'; } finally { echo "finally\n"; @@ -446,7 +446,7 @@ function generate() try { yield 1; yield 2; - } catch (\Exception $e) { + } catch (Exception $e) { echo 'catch'; } finally { echo "inner finally\n";