Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <laruence> [07:32:25] https://bugs.php.net/bug.php?id=62404
- <laruence> [07:33:03] I'd like to do this RFC, but I got really busy these days, anyone who also intereste of this FR?
- <ekneuss> [09:41:23] laruence, when would the check occur? At compile time? It would require some non-trivial analysis to be sound
- <laruence> [09:41:49] Hi, we can implement an easy check...
- <ekneuss> [09:42:05] afaik Java relies on the covariance of Exception effects, and that coupled with the type system allows for simple checks
- <laruence> [09:42:07] take all custom excetpions as Exception
- <laruence> [09:42:24] we can throw warning
- <ekneuss> [09:42:45] The problem is that to know if $foo->bar() will throw an exception, you need to know what type $foo is
- <laruence> [09:42:52] if a function declared throw excetpion but didn't wrapperd by try {} cache
- <laruence> [09:43:08] oh, I see your point
- <laruence> [09:43:32] both compiling time and run-time check?
- <laruence> [09:43:58] runtime check can be disabled through php.ini
- <ekneuss> [09:44:05] compile checks will only allow you to catch obvious throws within the same scope
- <ekneuss> [09:44:50] and I'm not sure how you would check that at runtime. It seems like you would only be able to do that if there is in fact an exception being thrown
- <ekneuss> [09:45:32] or maybe by inspecting the opcodes you can know if an exception may be thrown, but all in all it sounds fishy and very limitted
- <laruence> [09:46:23] zend_try -> set a global flag. do_fcall check op_array->throws and EG(in_try_block)
- <laruence> [09:46:58] if (op_array->throws && !EG(in_try_block)) -> php_error_docref
- <laruence> [09:47:19] the check will be simply, what do you think?
- <ekneuss> [09:47:21] but what exactly would that warning tell you that the exception itself wouldn't ?
- <laruence> [09:48:11] sorry, didn't understand your works (poor english of mine), you mean the custom exception type"
- <laruence> [09:48:11] ?
- <laruence> [09:48:19] s ,works,words,
- <ekneuss> [09:48:57] My point is, if your runtime check only triggers a warning whenever an exception is infact thrown in an "unchecked" (unnanontated function), it is of little use IMO
- <ekneuss> [09:49:19] because you have the exception as witness already, the warning will not add much
- <laruence> [09:49:54] no, exception doesn't always be throwed , right?
- <ekneuss> [09:50:18] but there is no reliable way to know whether an exception will be thrown without executing the code
- <laruence> [09:50:23] warning can help you , find the missed uncaught exception
- <ekneuss> [09:50:38] i.e. function foo() { if (false) throw Exception }
- <laruence> [09:50:58] yes, if you declaraed your function may throw exception.
- <laruence> [09:51:16] then we should tell peplop , hi, use a try block wrapp that function call.
- <ekneuss> [09:51:28] what about function bar($o, $i) { if ($i == 42) $o->someFunctionThrowing(); }
- <laruence> [09:51:28] it may throw exceptions
- <laruence> [09:52:09] yeah, a warning will throw, like , someFunctionTrhwoing may throw exceptions, please use a try block to catch it
- <laruence> [09:52:42] my point is , tell people which function/method may throw exceptions.
- <laruence> [09:52:49] to avoid uncaught exceptions
- <laruence> [09:53:12] I think this is the FR's point, right?
- <ekneuss> [09:53:21] right, but would you throw a warning for bar() ?
- <laruence> [09:53:32] no.
- <laruence> [09:53:41] only throw in bar.
- <ekneuss> [09:54:00] ok, now what if at runtime it turns out that $o->someFunctionThrowing() is declared as "throws Exception" ?
- <ekneuss> [09:54:03] no warning ?
- <laruence> [09:54:35] the warning is throwed in bar block
- <laruence> [09:54:49] only throw for somefunctionthroinng
- <ekneuss> [09:55:08] so in both case a warning would be emmited for the code of bar() {.. } ?
- <laruence> [09:55:40] oh, you mean, only $i == 42,
- <laruence> [09:55:43] ?
- <laruence> [09:56:10] if $i != 42, no warning throw?
- <ekneuss> [09:56:16] that's my question
- <laruence> [09:56:16] is that your point?
- <laruence> [09:56:29] if runtime.
- <ekneuss> [09:56:42] would you throw a warning in all cases because $i might be 42 and $o->someFunctionThrowing() might throw an exception ?
- <laruence> [09:56:46] then, the warning only throw when $i==42
- <laruence> [09:57:12] I think I got your point...
- <laruence> [09:58:06] if we do it in run-time phase
- <laruence> [09:58:29] I think the warning can only be triggerd while $i==42
- <ekneuss> [09:58:40] that would be possible in theory
- <laruence> [09:58:43] otherwise, the execution flow can not flow to it..
- <ekneuss> [09:59:30] does exceptions currently use longjmp or other magic to directly target the exception handler, or does it simply pop each stack frame until it reaches one ?
- <laruence> [09:59:49] for php opcode
- <ekneuss> [09:59:54] because that might be an implementation difficulty if you go for runtime checks
- <laruence> [09:59:55] throw exception
- <laruence> [10:00:02] will alter the op_array
- <laruence> [10:00:11] no, will alter the next oplien
- <ekneuss> [10:00:49] so the fcall handler terminates gracefully even in the case of an exception ?
- <laruence> [10:02:03] sure,
- <laruence> [10:02:09] since 5.4,
- <laruence> [10:02:13] EG(exception_op)
- <laruence> [10:02:26] can be used as the flag I said
- <ekneuss> [10:02:37] ok, I wasn't sure
- <ekneuss> [10:03:04] I'm still a tad bit dubious about the benefits of a runtime-check of the sort, it seems to me that it wouldn't add much relevant information, but could quickly become annoying instead
- <laruence> [10:03:05] thanks for your questions, they are very usful :)
- <laruence> [10:03:42] then, trigger NOTICE instead :)
- <ekneuss> [10:03:46] hehe
- <laruence> [10:03:48] heh
- <ekneuss> [10:05:34] basically, if you implement this feature, you will 1) have no guarantee before execution that you have no unhandled exceptions 2) if you have an unhandled exception, youwill see this because, erm, you have the unhandled exception with the full stack trace, so you don't really need the warning
- <ekneuss> [10:06:33] only in some limitted cases will you have the warning alone, without any concrete exception as witness
- <***> Playback Complete.
- <ekneuss> and all that assumes limitted check on exceptions handling, since you consider one exception handling as handling all types of exceptions.
- * lsmith has quit (Leaving...)
- <ekneuss> so function foo($i) { try { if ($i == 42) throw new ExceptionA(); } catch (ExceptionB $b) { ..} } would not trigger a warning, until you call that function with $i == 42.
- <laruence> if we introduce autoload for that check
- <laruence> we can implement the exception type checking
- <laruence> but I think it will be a little complicated , and bring performance slow down...
- <ekneuss> but that owuld be at runtime again
- <laruence> yes...
- <ekneuss> because throw $o; is vey well possible
- <ekneuss> so basically the only case where you can know that an exception was thrown is if it is actually thrown ?
- * moriyoshi (~Adium@s162.GtokyoFL26.vectant.ne.jp) has joined #php.pecl
- <laruence> hmm, that is really a promble....
- <laruence> since before zend_catch executing, I have no idea, what exception will be caught
- <ekneuss> Well, in most cases I assume people will use throw new Foo(); so by looking at the opcode you can know what type will be thrown
- <ekneuss> and then based on thw thrown type, you will have to inspect the opcodes to check if it is later handled
- <ekneuss> It seems to me that throwing an exception and catching it in the same scope represents a minority of exception usages, though
- <laruence> yes...I got you point, I will do some research later
- <laruence> :)
- <ekneuss> ok :)
- <laruence> thanks :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement