semiReserved.test 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. Valid usages of reserved keywords as identifiers
  2. -----
  3. <?php
  4. class Test {
  5. function array() {}
  6. function public() {}
  7. static function list() {}
  8. static function protected() {}
  9. public $class;
  10. public $private;
  11. const TRAIT = 3, FINAL = 4;
  12. const __CLASS__ = 1, __TRAIT__ = 2, __FUNCTION__ = 3, __METHOD__ = 4, __LINE__ = 5,
  13. __FILE__ = 6, __DIR__ = 7, __NAMESPACE__ = 8;
  14. // __halt_compiler does not work
  15. }
  16. $t = new Test;
  17. $t->array();
  18. $t->public();
  19. Test::list();
  20. Test::protected();
  21. $t->class;
  22. $t->private;
  23. Test::TRAIT;
  24. Test::FINAL;
  25. class Foo {
  26. use TraitA, TraitB {
  27. TraitA::catch insteadof namespace\TraitB;
  28. TraitA::list as foreach;
  29. TraitB::throw as protected public;
  30. TraitB::self as protected;
  31. exit as die;
  32. \TraitC::exit as bye;
  33. namespace\TraitC::exit as byebye;
  34. TraitA::
  35. //
  36. /** doc comment */
  37. #
  38. catch /* comment */
  39. // comment
  40. # comment
  41. insteadof TraitB;
  42. }
  43. }
  44. -----
  45. array(
  46. 0: Stmt_Class(
  47. attrGroups: array(
  48. )
  49. flags: 0
  50. name: Identifier(
  51. name: Test
  52. )
  53. extends: null
  54. implements: array(
  55. )
  56. stmts: array(
  57. 0: Stmt_ClassMethod(
  58. attrGroups: array(
  59. )
  60. flags: 0
  61. byRef: false
  62. name: Identifier(
  63. name: array
  64. )
  65. params: array(
  66. )
  67. returnType: null
  68. stmts: array(
  69. )
  70. )
  71. 1: Stmt_ClassMethod(
  72. attrGroups: array(
  73. )
  74. flags: 0
  75. byRef: false
  76. name: Identifier(
  77. name: public
  78. )
  79. params: array(
  80. )
  81. returnType: null
  82. stmts: array(
  83. )
  84. )
  85. 2: Stmt_ClassMethod(
  86. attrGroups: array(
  87. )
  88. flags: STATIC (8)
  89. byRef: false
  90. name: Identifier(
  91. name: list
  92. )
  93. params: array(
  94. )
  95. returnType: null
  96. stmts: array(
  97. )
  98. )
  99. 3: Stmt_ClassMethod(
  100. attrGroups: array(
  101. )
  102. flags: STATIC (8)
  103. byRef: false
  104. name: Identifier(
  105. name: protected
  106. )
  107. params: array(
  108. )
  109. returnType: null
  110. stmts: array(
  111. )
  112. )
  113. 4: Stmt_Property(
  114. attrGroups: array(
  115. )
  116. flags: PUBLIC (1)
  117. type: null
  118. props: array(
  119. 0: PropertyItem(
  120. name: VarLikeIdentifier(
  121. name: class
  122. )
  123. default: null
  124. )
  125. )
  126. )
  127. 5: Stmt_Property(
  128. attrGroups: array(
  129. )
  130. flags: PUBLIC (1)
  131. type: null
  132. props: array(
  133. 0: PropertyItem(
  134. name: VarLikeIdentifier(
  135. name: private
  136. )
  137. default: null
  138. )
  139. )
  140. )
  141. 6: Stmt_ClassConst(
  142. attrGroups: array(
  143. )
  144. flags: 0
  145. type: null
  146. consts: array(
  147. 0: Const(
  148. name: Identifier(
  149. name: TRAIT
  150. )
  151. value: Scalar_Int(
  152. value: 3
  153. )
  154. )
  155. 1: Const(
  156. name: Identifier(
  157. name: FINAL
  158. )
  159. value: Scalar_Int(
  160. value: 4
  161. )
  162. )
  163. )
  164. )
  165. 7: Stmt_ClassConst(
  166. attrGroups: array(
  167. )
  168. flags: 0
  169. type: null
  170. consts: array(
  171. 0: Const(
  172. name: Identifier(
  173. name: __CLASS__
  174. )
  175. value: Scalar_Int(
  176. value: 1
  177. )
  178. )
  179. 1: Const(
  180. name: Identifier(
  181. name: __TRAIT__
  182. )
  183. value: Scalar_Int(
  184. value: 2
  185. )
  186. )
  187. 2: Const(
  188. name: Identifier(
  189. name: __FUNCTION__
  190. )
  191. value: Scalar_Int(
  192. value: 3
  193. )
  194. )
  195. 3: Const(
  196. name: Identifier(
  197. name: __METHOD__
  198. )
  199. value: Scalar_Int(
  200. value: 4
  201. )
  202. )
  203. 4: Const(
  204. name: Identifier(
  205. name: __LINE__
  206. )
  207. value: Scalar_Int(
  208. value: 5
  209. )
  210. )
  211. 5: Const(
  212. name: Identifier(
  213. name: __FILE__
  214. )
  215. value: Scalar_Int(
  216. value: 6
  217. )
  218. )
  219. 6: Const(
  220. name: Identifier(
  221. name: __DIR__
  222. )
  223. value: Scalar_Int(
  224. value: 7
  225. )
  226. )
  227. 7: Const(
  228. name: Identifier(
  229. name: __NAMESPACE__
  230. )
  231. value: Scalar_Int(
  232. value: 8
  233. )
  234. )
  235. )
  236. )
  237. 8: Stmt_Nop(
  238. comments: array(
  239. 0: // __halt_compiler does not work
  240. )
  241. )
  242. )
  243. )
  244. 1: Stmt_Expression(
  245. expr: Expr_Assign(
  246. var: Expr_Variable(
  247. name: t
  248. )
  249. expr: Expr_New(
  250. class: Name(
  251. name: Test
  252. )
  253. args: array(
  254. )
  255. )
  256. )
  257. )
  258. 2: Stmt_Expression(
  259. expr: Expr_MethodCall(
  260. var: Expr_Variable(
  261. name: t
  262. )
  263. name: Identifier(
  264. name: array
  265. )
  266. args: array(
  267. )
  268. )
  269. )
  270. 3: Stmt_Expression(
  271. expr: Expr_MethodCall(
  272. var: Expr_Variable(
  273. name: t
  274. )
  275. name: Identifier(
  276. name: public
  277. )
  278. args: array(
  279. )
  280. )
  281. )
  282. 4: Stmt_Expression(
  283. expr: Expr_StaticCall(
  284. class: Name(
  285. name: Test
  286. )
  287. name: Identifier(
  288. name: list
  289. )
  290. args: array(
  291. )
  292. )
  293. )
  294. 5: Stmt_Expression(
  295. expr: Expr_StaticCall(
  296. class: Name(
  297. name: Test
  298. )
  299. name: Identifier(
  300. name: protected
  301. )
  302. args: array(
  303. )
  304. )
  305. )
  306. 6: Stmt_Expression(
  307. expr: Expr_PropertyFetch(
  308. var: Expr_Variable(
  309. name: t
  310. )
  311. name: Identifier(
  312. name: class
  313. )
  314. )
  315. )
  316. 7: Stmt_Expression(
  317. expr: Expr_PropertyFetch(
  318. var: Expr_Variable(
  319. name: t
  320. )
  321. name: Identifier(
  322. name: private
  323. )
  324. )
  325. )
  326. 8: Stmt_Expression(
  327. expr: Expr_ClassConstFetch(
  328. class: Name(
  329. name: Test
  330. )
  331. name: Identifier(
  332. name: TRAIT
  333. )
  334. )
  335. )
  336. 9: Stmt_Expression(
  337. expr: Expr_ClassConstFetch(
  338. class: Name(
  339. name: Test
  340. )
  341. name: Identifier(
  342. name: FINAL
  343. )
  344. )
  345. )
  346. 10: Stmt_Class(
  347. attrGroups: array(
  348. )
  349. flags: 0
  350. name: Identifier(
  351. name: Foo
  352. )
  353. extends: null
  354. implements: array(
  355. )
  356. stmts: array(
  357. 0: Stmt_TraitUse(
  358. traits: array(
  359. 0: Name(
  360. name: TraitA
  361. )
  362. 1: Name(
  363. name: TraitB
  364. )
  365. )
  366. adaptations: array(
  367. 0: Stmt_TraitUseAdaptation_Precedence(
  368. trait: Name(
  369. name: TraitA
  370. )
  371. method: Identifier(
  372. name: catch
  373. )
  374. insteadof: array(
  375. 0: Name_Relative(
  376. name: TraitB
  377. )
  378. )
  379. )
  380. 1: Stmt_TraitUseAdaptation_Alias(
  381. trait: Name(
  382. name: TraitA
  383. )
  384. method: Identifier(
  385. name: list
  386. )
  387. newModifier: null
  388. newName: Identifier(
  389. name: foreach
  390. )
  391. )
  392. 2: Stmt_TraitUseAdaptation_Alias(
  393. trait: Name(
  394. name: TraitB
  395. )
  396. method: Identifier(
  397. name: throw
  398. )
  399. newModifier: PROTECTED (2)
  400. newName: Identifier(
  401. name: public
  402. )
  403. )
  404. 3: Stmt_TraitUseAdaptation_Alias(
  405. trait: Name(
  406. name: TraitB
  407. )
  408. method: Identifier(
  409. name: self
  410. )
  411. newModifier: PROTECTED (2)
  412. newName: null
  413. )
  414. 4: Stmt_TraitUseAdaptation_Alias(
  415. trait: null
  416. method: Identifier(
  417. name: exit
  418. )
  419. newModifier: null
  420. newName: Identifier(
  421. name: die
  422. )
  423. )
  424. 5: Stmt_TraitUseAdaptation_Alias(
  425. trait: Name_FullyQualified(
  426. name: TraitC
  427. )
  428. method: Identifier(
  429. name: exit
  430. )
  431. newModifier: null
  432. newName: Identifier(
  433. name: bye
  434. )
  435. )
  436. 6: Stmt_TraitUseAdaptation_Alias(
  437. trait: Name_Relative(
  438. name: TraitC
  439. )
  440. method: Identifier(
  441. name: exit
  442. )
  443. newModifier: null
  444. newName: Identifier(
  445. name: byebye
  446. )
  447. )
  448. 7: Stmt_TraitUseAdaptation_Precedence(
  449. trait: Name(
  450. name: TraitA
  451. )
  452. method: Identifier(
  453. name: catch
  454. comments: array(
  455. 0: //
  456. 1: /** doc comment */
  457. 2: #
  458. )
  459. )
  460. insteadof: array(
  461. 0: Name(
  462. name: TraitB
  463. )
  464. )
  465. )
  466. )
  467. )
  468. )
  469. )
  470. )