spl_autoload_007.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. --TEST--
  2. SPL: spl_autoload() with inaccessible methods
  3. --INI--
  4. include_path=.
  5. --FILE--
  6. <?php
  7. class MyAutoLoader {
  8. static protected function noAccess($className) {
  9. echo __METHOD__ . "($className)\n";
  10. }
  11. static function autoLoad($className) {
  12. echo __METHOD__ . "($className)\n";
  13. }
  14. function dynaLoad($className) {
  15. echo __METHOD__ . "($className)\n";
  16. }
  17. }
  18. $obj = new MyAutoLoader;
  19. $funcs = array(
  20. 'MyAutoLoader::notExist',
  21. 'MyAutoLoader::noAccess',
  22. 'MyAutoLoader::autoLoad',
  23. 'MyAutoLoader::dynaLoad',
  24. array('MyAutoLoader', 'notExist'),
  25. array('MyAutoLoader', 'noAccess'),
  26. array('MyAutoLoader', 'autoLoad'),
  27. array('MyAutoLoader', 'dynaLoad'),
  28. array($obj, 'notExist'),
  29. array($obj, 'noAccess'),
  30. array($obj, 'autoLoad'),
  31. array($obj, 'dynaLoad'),
  32. );
  33. foreach($funcs as $idx => $func)
  34. {
  35. if ($idx) echo "\n";
  36. try {
  37. var_dump($func);
  38. spl_autoload_register($func);
  39. echo "ok\n";
  40. } catch(\TypeError $e) {
  41. echo $e->getMessage() . \PHP_EOL;
  42. }
  43. }
  44. ?>
  45. --EXPECTF--
  46. string(22) "MyAutoLoader::notExist"
  47. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist"
  48. string(22) "MyAutoLoader::noAccess"
  49. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess()
  50. string(22) "MyAutoLoader::autoLoad"
  51. ok
  52. string(22) "MyAutoLoader::dynaLoad"
  53. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically
  54. array(2) {
  55. [0]=>
  56. string(12) "MyAutoLoader"
  57. [1]=>
  58. string(8) "notExist"
  59. }
  60. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist"
  61. array(2) {
  62. [0]=>
  63. string(12) "MyAutoLoader"
  64. [1]=>
  65. string(8) "noAccess"
  66. }
  67. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess()
  68. array(2) {
  69. [0]=>
  70. string(12) "MyAutoLoader"
  71. [1]=>
  72. string(8) "autoLoad"
  73. }
  74. ok
  75. array(2) {
  76. [0]=>
  77. string(12) "MyAutoLoader"
  78. [1]=>
  79. string(8) "dynaLoad"
  80. }
  81. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically
  82. array(2) {
  83. [0]=>
  84. object(MyAutoLoader)#%d (0) {
  85. }
  86. [1]=>
  87. string(8) "notExist"
  88. }
  89. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist"
  90. array(2) {
  91. [0]=>
  92. object(MyAutoLoader)#%d (0) {
  93. }
  94. [1]=>
  95. string(8) "noAccess"
  96. }
  97. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess()
  98. array(2) {
  99. [0]=>
  100. object(MyAutoLoader)#%d (0) {
  101. }
  102. [1]=>
  103. string(8) "autoLoad"
  104. }
  105. ok
  106. array(2) {
  107. [0]=>
  108. object(MyAutoLoader)#%d (0) {
  109. }
  110. [1]=>
  111. string(8) "dynaLoad"
  112. }
  113. ok