Advertisement
laruence

Untitled

Jun 25th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. <laruence> [07:32:25] https://bugs.php.net/bug.php?id=62404
  2. <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?
  3. <ekneuss> [09:41:23] laruence, when would the check occur? At compile time? It would require some non-trivial analysis to be sound
  4. <laruence> [09:41:49] Hi, we can implement an easy check...
  5. <ekneuss> [09:42:05] afaik Java relies on the covariance of Exception effects, and that coupled with the type system allows for simple checks
  6. <laruence> [09:42:07] take all custom excetpions as Exception
  7. <laruence> [09:42:24] we can throw warning
  8. <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
  9. <laruence> [09:42:52] if a function declared throw excetpion but didn't wrapperd by try {} cache
  10. <laruence> [09:43:08] oh, I see your point
  11. <laruence> [09:43:32] both compiling time and run-time check?
  12. <laruence> [09:43:58] runtime check can be disabled through php.ini
  13. <ekneuss> [09:44:05] compile checks will only allow you to catch obvious throws within the same scope
  14. <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
  15. <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
  16. <laruence> [09:46:23] zend_try -> set a global flag. do_fcall check op_array->throws and EG(in_try_block)
  17. <laruence> [09:46:58] if (op_array->throws && !EG(in_try_block)) -> php_error_docref
  18. <laruence> [09:47:19] the check will be simply, what do you think?
  19. <ekneuss> [09:47:21] but what exactly would that warning tell you that the exception itself wouldn't ?
  20. <laruence> [09:48:11] sorry, didn't understand your works (poor english of mine), you mean the custom exception type"
  21. <laruence> [09:48:11] ?
  22. <laruence> [09:48:19] s ,works,words,
  23. <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
  24. <ekneuss> [09:49:19] because you have the exception as witness already, the warning will not add much
  25. <laruence> [09:49:54] no, exception doesn't always be throwed , right?
  26. <ekneuss> [09:50:18] but there is no reliable way to know whether an exception will be thrown without executing the code
  27. <laruence> [09:50:23] warning can help you , find the missed uncaught exception
  28. <ekneuss> [09:50:38] i.e. function foo() { if (false) throw Exception }
  29. <laruence> [09:50:58] yes, if you declaraed your function may throw exception.
  30. <laruence> [09:51:16] then we should tell peplop , hi, use a try block wrapp that function call.
  31. <ekneuss> [09:51:28] what about function bar($o, $i) { if ($i == 42) $o->someFunctionThrowing(); }
  32. <laruence> [09:51:28] it may throw exceptions
  33. <laruence> [09:52:09] yeah, a warning will throw, like , someFunctionTrhwoing may throw exceptions, please use a try block to catch it
  34. <laruence> [09:52:42] my point is , tell people which function/method may throw exceptions.
  35. <laruence> [09:52:49] to avoid uncaught exceptions
  36. <laruence> [09:53:12] I think this is the FR's point, right?
  37. <ekneuss> [09:53:21] right, but would you throw a warning for bar() ?
  38. <laruence> [09:53:32] no.
  39. <laruence> [09:53:41] only throw in bar.
  40. <ekneuss> [09:54:00] ok, now what if at runtime it turns out that $o->someFunctionThrowing() is declared as "throws Exception" ?
  41. <ekneuss> [09:54:03] no warning ?
  42. <laruence> [09:54:35] the warning is throwed in bar block
  43. <laruence> [09:54:49] only throw for somefunctionthroinng
  44. <ekneuss> [09:55:08] so in both case a warning would be emmited for the code of bar() {.. } ?
  45. <laruence> [09:55:40] oh, you mean, only $i == 42,
  46. <laruence> [09:55:43] ?
  47. <laruence> [09:56:10] if $i != 42, no warning throw?
  48. <ekneuss> [09:56:16] that's my question
  49. <laruence> [09:56:16] is that your point?
  50. <laruence> [09:56:29] if runtime.
  51. <ekneuss> [09:56:42] would you throw a warning in all cases because $i might be 42 and $o->someFunctionThrowing() might throw an exception ?
  52. <laruence> [09:56:46] then, the warning only throw when $i==42
  53. <laruence> [09:57:12] I think I got your point...
  54. <laruence> [09:58:06] if we do it in run-time phase
  55. <laruence> [09:58:29] I think the warning can only be triggerd while $i==42
  56. <ekneuss> [09:58:40] that would be possible in theory
  57. <laruence> [09:58:43] otherwise, the execution flow can not flow to it..
  58. <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 ?
  59. <laruence> [09:59:49] for php opcode
  60. <ekneuss> [09:59:54] because that might be an implementation difficulty if you go for runtime checks
  61. <laruence> [09:59:55] throw exception
  62. <laruence> [10:00:02] will alter the op_array
  63. <laruence> [10:00:11] no, will alter the next oplien
  64. <ekneuss> [10:00:49] so the fcall handler terminates gracefully even in the case of an exception ?
  65. <laruence> [10:02:03] sure,
  66. <laruence> [10:02:09] since 5.4,
  67. <laruence> [10:02:13] EG(exception_op)
  68. <laruence> [10:02:26] can be used as the flag I said
  69. <ekneuss> [10:02:37] ok, I wasn't sure
  70. <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
  71. <laruence> [10:03:05] thanks for your questions, they are very usful :)
  72. <laruence> [10:03:42] then, trigger NOTICE instead :)
  73. <ekneuss> [10:03:46] hehe
  74. <laruence> [10:03:48] heh
  75. <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
  76. <ekneuss> [10:06:33] only in some limitted cases will you have the warning alone, without any concrete exception as witness
  77. <***> Playback Complete.
  78. <ekneuss> and all that assumes limitted check on exceptions handling, since you consider one exception handling as handling all types of exceptions.
  79. * lsmith has quit (Leaving...)
  80. <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.
  81. <laruence> if we introduce autoload for that check
  82. <laruence> we can implement the exception type checking
  83. <laruence> but I think it will be a little complicated , and bring performance slow down...
  84. <ekneuss> but that owuld be at runtime again
  85. <laruence> yes...
  86. <ekneuss> because throw $o; is vey well possible
  87. <ekneuss> so basically the only case where you can know that an exception was thrown is if it is actually thrown ?
  88. * moriyoshi (~Adium@s162.GtokyoFL26.vectant.ne.jp) has joined #php.pecl
  89. <laruence> hmm, that is really a promble....
  90. <laruence> since before zend_catch executing, I have no idea, what exception will be caught
  91. <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
  92. <ekneuss> and then based on thw thrown type, you will have to inspect the opcodes to check if it is later handled
  93. <ekneuss> It seems to me that throwing an exception and catching it in the same scope represents a minority of exception usages, though
  94. <laruence> yes...I got you point, I will do some research later
  95. <laruence> :)
  96. <ekneuss> ok :)
  97. <laruence> thanks :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement