__call_007.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. object(A)#1 (0) {
  52. }
  53. Exception caught OK; continuing.
  54. ---> Invoke __call via scope resolution operator within instance.
  55. object(A)#1 (0) {
  56. }
  57. Exception caught OK; continuing.
  58. ---> Invoke __call via scope resolution operator within child instance.
  59. object(B)#2 (0) {
  60. }
  61. Exception caught OK; continuing.
  62. ---> Invoke __call via callback.
  63. object(B)#2 (0) {
  64. }
  65. Exception caught OK; continuing.
  66. ==DONE==