Re: [RFC] Exception type hint
| From: | Guilliam Xavier | Date: | Wed, 29 Jun 2022 15:42:46 +0000 |
| Subject: | Re: [RFC] Exception type hint | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118121@lists.php.net to get a copy of this message | ||
Hi (note: your message was flagged as spam),
> https://github.com/php/php-src/issues/8843
So I understand it as having a "true code" equivalent for the
@throws phpDoc comment (similar to type declarations for @param
and @return)? which would also be checked at run-time?
Just my 2 cents on that (let's call it "exception specification"):
1. IMHO, it shouldn't be mixed in the return type declaration (with
a union-like syntax) but separated and independent (e.g. with a
throws keyword, and pipes [or commas] between multiple exception
classes)
2. AFAIK, Java has it (mandatory to compile for "checked
exceptions", sometimes controversial), C++ used to have it
(runtime-checked) but dropped it (and introduced noexcept instead);
I don't know of any dynamic language that has it
You would also need to define how it plays with inheritance (and
reflection), and what exactly should happen when a function throws an
exception it didn't "declare"...
PS: I also found some old feature requests:
- https://externals.io/message/4424
- https://bugs.php.net/bug.php?id=42251
- https://bugs.php.net/bug.php?id=62404
- https://bugs.php.net/bug.php?id=67312
Regards,
--
Guilliam Xavier