bug48770_2.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Bug #48770 (call_user_func_array() fails to call parent from inheriting class)
  3. --FILE--
  4. <?php
  5. class A {
  6. public function func($str) {
  7. var_dump(__METHOD__ .': '. $str);
  8. }
  9. private function func2($str) {
  10. var_dump(__METHOD__ .': '. $str);
  11. }
  12. protected function func3($str) {
  13. var_dump(__METHOD__ .': '. $str);
  14. }
  15. private function func22($str) {
  16. var_dump(__METHOD__ .': '. $str);
  17. }
  18. }
  19. class B extends A {
  20. public function func($str) {
  21. call_user_func_array(array($this, 'parent::func2'), array($str));
  22. call_user_func_array(array($this, 'parent::func3'), array($str));
  23. try {
  24. call_user_func_array(array($this, 'parent::func22'), array($str));
  25. } catch (\TypeError $e) {
  26. echo $e->getMessage() . \PHP_EOL;
  27. }
  28. try {
  29. call_user_func_array(array($this, 'parent::inexistent'), array($str));
  30. } catch (\TypeError $e) {
  31. echo $e->getMessage() . \PHP_EOL;
  32. }
  33. }
  34. private function func2($str) {
  35. var_dump(__METHOD__ .': '. $str);
  36. }
  37. protected function func3($str) {
  38. var_dump(__METHOD__ .': '. $str);
  39. }
  40. }
  41. class C extends B {
  42. public function func($str) {
  43. parent::func($str);
  44. }
  45. }
  46. $c = new C;
  47. $c->func('This should work!');
  48. ?>
  49. --EXPECT--
  50. string(27) "B::func2: This should work!"
  51. string(27) "B::func3: This should work!"
  52. call_user_func_array(): Argument #1 ($callback) must be a valid callback, cannot access private method B::func22()
  53. call_user_func_array(): Argument #1 ($callback) must be a valid callback, class B does not have a method "inexistent"