__call_007.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Ensure exceptions are handled properly when thrown in a statically declared __call.
  3. --FILE--
  4. <?php
  5. class A {
  6. static function __call($strMethod, $arrArgs) {
  7. @var_dump($this);
  8. throw new Exception;
  9. echo "You should not see this";
  10. }
  11. function test() {
  12. A::unknownCalledWithSRO(1,2,3);
  13. }
  14. }
  15. class B extends A {
  16. function test() {
  17. B::unknownCalledWithSROFromChild(1,2,3);
  18. }
  19. }
  20. $a = new A();
  21. echo "---> Invoke __call via simple method call.\n";
  22. try {
  23. $a->unknown();
  24. } catch (Exception $e) {
  25. echo "Exception caught OK; continuing.\n";
  26. }
  27. echo "\n\n---> Invoke __call via scope resolution operator within instance.\n";
  28. try {
  29. $a->test();
  30. } catch (Exception $e) {
  31. echo "Exception caught OK; continuing.\n";
  32. }
  33. echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n";
  34. $b = new B();
  35. try {
  36. $b->test();
  37. } catch (Exception $e) {
  38. echo "Exception caught OK; continuing.\n";
  39. }
  40. echo "\n\n---> Invoke __call via callback.\n";
  41. try {
  42. call_user_func(array($b, 'unknownCallback'), 1,2,3);
  43. } catch (Exception $e) {
  44. echo "Exception caught OK; continuing.\n";
  45. }
  46. ?>
  47. ==DONE==
  48. --EXPECTF--
  49. Warning: The magic method __call() must have public visibility and cannot be static in %s on line 3
  50. ---> Invoke __call via simple method call.
  51. NULL
  52. Exception caught OK; continuing.
  53. ---> Invoke __call via scope resolution operator within instance.
  54. NULL
  55. Exception caught OK; continuing.
  56. ---> Invoke __call via scope resolution operator within child instance.
  57. NULL
  58. Exception caught OK; continuing.
  59. ---> Invoke __call via callback.
  60. NULL
  61. Exception caught OK; continuing.
  62. ==DONE==