Re: Type hinting
| From: | Chad Fulton | Date: | Tue, 01 Jun 2010 22:49:32 +0000 |
| Subject: | Re: Type hinting | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48599@lists.php.net to get a copy of this message | ||
Hello!
> As I mentioned, I think that we have to inform the caller about the problem
> (be either a type or a conversion mismatch), so the only options to trigger
> an error, or throw an exception.
> I like the exception idea better, because it can be easily handled localy
> (no need to register a global error handler), but as the core devs said, it
> isn't allowed to throw exceptions from the core, so this is why I think,
> that the weak type hinting should be implemented as an spl interface.
> This way we could even support array - ArrayObject conversion too.
>
> http://wiki.php.net/rfc/splweaktypehintingwithautoboxing
I'm not sure what is being added by using the SPL interface except a
way to justify throwing exceptions on type mismatch with data loss?
The only reason I can think of for throwing exceptions in this case
would be data validation purposes, which I think is not the intention
of type hinting, and also not the intention of exceptions (users
inputting bad data is not an *exceptional* occurrence imo).
Is there some other reason / use case for wanting exceptions? So, I
mean, where is the use case where '123abc' will be passed to a
type-hinted field where you could catch the exception and do something
meaningful to carry on with the execution of the program other than
simply error-ing out?