fork download
  1. <?php
  2.  
  3. class PHPReservedWords {
  4. public function isWordReserved($args) {
  5. $word = $args['word'];
  6.  
  7. if($this->GetPHPReservedWordsHash()[$word]) {
  8. return TRUE;
  9. }
  10.  
  11. return FALSE;
  12. }
  13.  
  14. public function GetPHPReservedWordsHash() {
  15. if($this->word_hash) {
  16. return $this->word_hash;
  17. }
  18.  
  19. $hash = [];
  20.  
  21. foreach($this->GetPHPReservedWords() as $word) {
  22. $hash[$word] = TRUE;
  23. }
  24.  
  25. return $this->word_hash = $hash;
  26. }
  27. public function GetPHPReservedWords() {
  28. return [
  29. # Primary Source: https://w...content-available-to-author-only...p.net/manual/en/reserved.php
  30. # ----------------------------------------------------------
  31.  
  32. # List 1 of 4: https://w...content-available-to-author-only...p.net/manual/en/reserved.keywords.php
  33. # ----------------------------------------------------------------
  34.  
  35. '__halt_compiler',
  36. 'abstract',
  37. 'and',
  38. 'array',
  39. 'as',
  40. 'break',
  41. 'callable',
  42. 'case',
  43. 'catch',
  44. 'class',
  45. 'clone',
  46. 'const',
  47. 'continue',
  48. 'declare',
  49. 'default',
  50. 'die',
  51. 'do',
  52. 'echo',
  53. 'else',
  54. 'elseif',
  55. 'empty',
  56. 'enddeclare',
  57. 'endfor',
  58. 'endforeach',
  59. 'endif',
  60. 'endswitch',
  61. 'endwhile',
  62. 'eval',
  63. 'exit',
  64. 'extends',
  65. 'final',
  66. 'finally',
  67. 'fn', # (as of PHP 7.4)
  68. 'for',
  69. 'foreach',
  70. 'function',
  71. 'global',
  72. 'goto',
  73. 'if',
  74. 'implements',
  75. 'include',
  76. 'include_once',
  77. 'instanceof',
  78. 'insteadof',
  79. 'interface',
  80. 'isset',
  81. 'list',
  82. 'match', # (as of PHP 8.0)
  83. 'namespace',
  84. 'new',
  85. 'or',
  86. 'print',
  87. 'private',
  88. 'protected',
  89. 'public',
  90. 'readonly', # (as of PHP 8.1.0)
  91. 'require',
  92. 'require_once',
  93. 'return',
  94. 'static',
  95. 'switch',
  96. 'throw',
  97. 'trait',
  98. 'try',
  99. 'unset()',
  100. 'use',
  101. 'var',
  102. 'while',
  103. 'xor',
  104. 'yield',
  105. 'yield from',
  106.  
  107. # List 2 of 4: https://w...content-available-to-author-only...p.net/manual/en/reserved.classes.php
  108. # ---------------------------------------------------------------
  109.  
  110. 'Directory',
  111. 'stdClass',
  112. '__PHP_Incomplete_Class',
  113. 'Exception',
  114. 'ErrorException',
  115. 'php_user_filter',
  116. 'Closure',
  117. 'Generator',
  118. 'ArithmeticError',
  119. 'AssertionError',
  120. 'DivisionByZeroError',
  121. 'Error',
  122. 'Throwable',
  123. 'ParseError',
  124. 'TypeError',
  125. 'self',
  126. 'static',
  127. 'parent',
  128.  
  129. # List 3 of 4: https://w...content-available-to-author-only...p.net/manual/en/reserved.constants.php
  130. # ---------------------------------------------------------------
  131.  
  132. 'PHP_VERSION',
  133. 'PHP_MAJOR_VERSION',
  134. 'PHP_MINOR_VERSION',
  135. 'PHP_RELEASE_VERSION',
  136. 'PHP_VERSION_ID',
  137. 'PHP_EXTRA_VERSION',
  138. 'PHP_ZTS',
  139. 'PHP_DEBUG',
  140. 'PHP_MAXPATHLEN',
  141. 'PHP_OS',
  142. 'PHP_OS_FAMILY',
  143. 'PHP_SAPI',
  144. 'PHP_EOL',
  145. 'PHP_INT_MAX',
  146. 'PHP_INT_MIN',
  147. 'PHP_INT_SIZE',
  148. 'PHP_FLOAT_DIG',
  149. 'PHP_FLOAT_EPSILON',
  150. 'PHP_FLOAT_MIN',
  151. 'PHP_FLOAT_MAX',
  152. 'DEFAULT_INCLUDE_PATH',
  153. 'PEAR_INSTALL_DIR',
  154. 'PEAR_EXTENSION_DIR',
  155. 'PHP_EXTENSION_DIR',
  156. 'PHP_PREFIX',
  157. 'PHP_BINDIR',
  158. 'PHP_BINARY',
  159. 'PHP_MANDIR',
  160. 'PHP_LIBDIR',
  161. 'PHP_DATADIR',
  162. 'PHP_SYSCONFDIR',
  163. 'PHP_LOCALSTATEDIR',
  164. 'PHP_CONFIG_FILE_PATH',
  165. 'PHP_CONFIG_FILE_SCAN_DIR',
  166. 'PHP_SHLIB_SUFFIX',
  167. 'PHP_FD_SETSIZE',
  168. 'E_ERROR',
  169. 'E_WARNING',
  170. 'E_PARSE',
  171. 'E_NOTICE',
  172. 'E_CORE_ERROR',
  173. 'E_CORE_WARNING',
  174. 'E_COMPILE_ERROR',
  175. 'E_COMPILE_WARNING',
  176. 'E_USER_ERROR',
  177. 'E_USER_WARNING',
  178. 'E_USER_NOTICE',
  179. 'E_RECOVERABLE_ERROR',
  180. 'E_DEPRECATED',
  181. 'E_USER_DEPRECATED',
  182. 'E_ALL',
  183. 'E_STRICT',
  184. 'true',
  185. 'false',
  186. 'null',
  187. 'PHP_WINDOWS_EVENT_CTRL_C',
  188. 'PHP_WINDOWS_EVENT_CTRL_BREAK',
  189.  
  190. # List 4 of 4: https://w...content-available-to-author-only...p.net/manual/en/reserved.other-reserved-words.php
  191. # ---------------------------------------------------------------
  192.  
  193. 'int',
  194. 'float',
  195. 'bool',
  196. 'string',
  197. 'true',
  198. 'false',
  199. 'null',
  200. 'void', # (as of PHP 7.1)
  201. 'iterable', # (as of PHP 7.1)
  202. 'object', # (as of PHP 7.2)
  203. 'resource',
  204. 'mixed',
  205. 'numeric',
  206. ];
  207. }
  208. }
  209.  
  210.  
  211. $reserved_words = new PHPReservedWords();
  212. print($reserved_words->isWordReserved(['word'=>'new']));
Success #stdin #stdout #stderr 0.02s 25768KB
stdin
Standard input is empty
stdout
1
stderr
PHP Notice:  Undefined property: PHPReservedWords::$word_hash in /home/8zy98Z/prog.php on line 15