PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/mysqli/tests/reflection_tools.inc

https://bitbucket.org/segv/php-src
PHP | 121 lines | 94 code | 23 blank | 4 comment | 8 complexity | 6333cb1a01ba5bf0803dbea89decfd57 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. function inspectClass($class) {
  3. /* not used: public ReflectionClass[] getInterfaces() */
  4. printf("\nInspecting class '%s'\n", $class->getName());
  5. printf("isInternal: %s\n", ($class->isInternal()) ? 'yes' : 'no');
  6. printf("isUserDefined: %s\n", ($class->isUserDefined()) ? 'yes' : 'no');
  7. printf("isInstantiable: %s\n", ($class->isInstantiable()) ? 'yes' : 'no');
  8. printf("isInterface: %s\n", ($class->isInterface()) ? 'yes' : 'no');
  9. printf("isAbstract: %s\n", ($class->isAbstract()) ? 'yes' : 'no');
  10. printf("isFinal: %s\n", ($class->isFinal()) ? 'yes' : 'no');
  11. printf("isIteratable: %s\n", ($class->isIterateable()) ? 'yes' : 'no');
  12. printf("Modifiers: '%d'\n", $class->getModifiers());
  13. printf("Parent Class: '%s'\n", $class->getParentClass());
  14. printf("Extension: '%s'\n", $class->getExtensionName());
  15. if ($method = $class->getConstructor())
  16. inspectMethod($method);
  17. if ($methods = $class->getMethods()) {
  18. $tmp = array();
  19. foreach ($methods as $method)
  20. $tmp[$method->getName()] = $method;
  21. ksort($tmp, SORT_STRING);
  22. foreach ($tmp as $method)
  23. inspectMethod($method);
  24. }
  25. if ($properties = $class->getProperties()) {
  26. $tmp = array();
  27. foreach ($properties as $prop)
  28. $tmp[$prop->getName()] = $prop;
  29. ksort($tmp, SORT_STRING);
  30. foreach ($tmp as $prop)
  31. inspectProperty($prop);
  32. }
  33. if ($properties = $class->getDefaultProperties()) {
  34. ksort($properties, SORT_STRING);
  35. foreach ($properties as $name => $v)
  36. printf("Default property '%s'\n", $name);
  37. }
  38. if ($properties = $class->getStaticProperties()) {
  39. ksort($properties, SORT_STRING);
  40. foreach ($properties as $name => $v)
  41. printf("Static property '%s'\n", $name);
  42. }
  43. if ($constants = $class->getConstants()) {
  44. ksort($constants, SORT_STRING);
  45. foreach ($constant as $name => $value)
  46. printf("Constant '%s' = '%s'\n", $name, $value);
  47. }
  48. }
  49. function inspectProperty(&$prop) {
  50. printf("\nInspecting property '%s'\n", $prop->getName());
  51. printf("isPublic: %s\n", ($prop->isPublic()) ? 'yes' : 'no');
  52. printf("isPrivate: %s\n", ($prop->isPrivate()) ? 'yes' : 'no');
  53. printf("isProtected: %s\n", ($prop->isProtected()) ? 'yes' : 'no');
  54. printf("isStatic: %s\n", ($prop->isStatic()) ? 'yes' : 'no');
  55. printf("isDefault: %s\n", ($prop->isDefault()) ? 'yes' : 'no');
  56. printf("Modifiers: %d\n", $prop->getModifiers());
  57. // printf("Value\n"); var_export($prop->getValue());
  58. }
  59. function inspectMethod(&$method) {
  60. printf("\nInspecting method '%s'\n", $method->getName());
  61. printf("isFinal: %s\n", ($method->isFinal()) ? 'yes' : 'no');
  62. printf("isAbstract: %s\n", ($method->isAbstract()) ? 'yes' : 'no');
  63. printf("isPublic: %s\n", ($method->isPublic()) ? 'yes' : 'no');
  64. printf("isPrivate: %s\n", ($method->isPrivate()) ? 'yes' : 'no');
  65. printf("isProtected: %s\n", ($method->isProtected()) ? 'yes' : 'no');
  66. printf("isStatic: %s\n", ($method->isStatic()) ? 'yes' : 'no');
  67. printf("isConstructor: %s\n", ($method->isConstructor()) ? 'yes' : 'no');
  68. printf("isDestructor: %s\n", ($method->isDestructor()) ? 'yes' : 'no');
  69. printf("isInternal: %s\n", ($method->isInternal()) ? 'yes' : 'no');
  70. printf("isUserDefined: %s\n", ($method->isUserDefined()) ? 'yes' : 'no');
  71. printf("returnsReference: %s\n", ($method->returnsReference()) ? 'yes' : 'no');
  72. printf("Modifiers: %d\n", $method->getModifiers());
  73. printf("Number of Parameters: %d\n", $method->getNumberOfParameters());
  74. printf("Number of Required Parameters: %d\n", $method->getNumberOfRequiredParameters());
  75. if ($params = $method->getParameters()) {
  76. $tmp = array();
  77. foreach ($params as $k => $param)
  78. $tmp[$param->getName()] = $param;
  79. // ksort($tmp, SORT_STRING);
  80. foreach ($tmp as $param)
  81. inspectParameter($method, $param);
  82. }
  83. if ($static = $method->getStaticVariables()) {
  84. sort($static, SORT_STRING);
  85. printf("Static variables: %s\n", implode('/', $static));
  86. }
  87. }
  88. function inspectParameter(&$method, &$param) {
  89. printf("\nInspecting parameter '%s' of method '%s'\n",
  90. $param->getName(), $method->getName());
  91. printf("isArray: %s\n", ($param->isArray()) ? 'yes': 'no');
  92. printf("allowsNull: %s\n", ($param->allowsNull()) ? 'yes' : 'no');
  93. printf("isPassedByReference: %s\n", ($param->isPassedByReference()) ? 'yes' : 'no');
  94. printf("isOptional: %s\n", ($param->isOptional()) ? 'yes' : 'no');
  95. printf("isDefaultValueAvailable: %s\n", ($param->isDefaultValueAvailable()) ? 'yes' : 'no');
  96. // printf("getDefaultValue: %s\n", ($param->getDefaultValue()) ? 'yes' : 'no');
  97. }
  98. ?>