call_user_func_001.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Testing call_user_func inside namespace
  3. --FILE--
  4. <?php
  5. namespace testing {
  6. function foobar($str) {
  7. var_dump($str);
  8. }
  9. abstract class bar {
  10. protected function prot($str) {
  11. print "Shouldn't be called!\n";
  12. }
  13. }
  14. class foo extends bar {
  15. private function priv($str) {
  16. print "Shouldn't be called!\n";
  17. }
  18. }
  19. call_user_func(__NAMESPACE__ .'\foobar', 'foobar');
  20. $class = __NAMESPACE__ .'\foo';
  21. try {
  22. call_user_func(array(new $class, 'priv'), 'foobar');
  23. } catch (\TypeError $e) {
  24. echo $e->getMessage(), "\n";
  25. }
  26. try {
  27. call_user_func(array(new $class, 'prot'), 'foobar');
  28. } catch (\TypeError $e) {
  29. echo $e->getMessage(), "\n";
  30. }
  31. }
  32. ?>
  33. --EXPECT--
  34. string(6) "foobar"
  35. call_user_func(): Argument #1 ($callback) must be a valid callback, cannot access private method testing\foo::priv()
  36. call_user_func(): Argument #1 ($callback) must be a valid callback, cannot access protected method testing\foo::prot()