zend_constants.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "zend.h"
  20. #include "zend_constants.h"
  21. #include "zend_exceptions.h"
  22. #include "zend_execute.h"
  23. #include "zend_variables.h"
  24. #include "zend_operators.h"
  25. #include "zend_globals.h"
  26. #include "zend_API.h"
  27. /* Protection from recursive self-referencing class constants */
  28. #define IS_CONSTANT_VISITED_MARK 0x80
  29. #define IS_CONSTANT_VISITED(zv) (Z_ACCESS_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
  30. #define MARK_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
  31. #define RESET_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
  32. void free_zend_constant(zval *zv)
  33. {
  34. zend_constant *c = Z_PTR_P(zv);
  35. if (!(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)) {
  36. zval_ptr_dtor_nogc(&c->value);
  37. if (c->name) {
  38. zend_string_release_ex(c->name, 0);
  39. }
  40. efree(c);
  41. } else {
  42. zval_internal_ptr_dtor(&c->value);
  43. if (c->name) {
  44. zend_string_release_ex(c->name, 1);
  45. }
  46. free(c);
  47. }
  48. }
  49. #ifdef ZTS
  50. static void copy_zend_constant(zval *zv)
  51. {
  52. zend_constant *c = Z_PTR_P(zv);
  53. ZEND_ASSERT(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
  54. Z_PTR_P(zv) = pemalloc(sizeof(zend_constant), 1);
  55. memcpy(Z_PTR_P(zv), c, sizeof(zend_constant));
  56. c = Z_PTR_P(zv);
  57. c->name = zend_string_copy(c->name);
  58. if (Z_TYPE(c->value) == IS_STRING) {
  59. Z_STR(c->value) = zend_string_dup(Z_STR(c->value), 1);
  60. }
  61. }
  62. void zend_copy_constants(HashTable *target, HashTable *source)
  63. {
  64. zend_hash_copy(target, source, copy_zend_constant);
  65. }
  66. #endif
  67. static int clean_module_constant(zval *el, void *arg)
  68. {
  69. zend_constant *c = (zend_constant *)Z_PTR_P(el);
  70. int module_number = *(int *)arg;
  71. if (ZEND_CONSTANT_MODULE_NUMBER(c) == module_number) {
  72. return 1;
  73. } else {
  74. return 0;
  75. }
  76. }
  77. void clean_module_constants(int module_number)
  78. {
  79. zend_hash_apply_with_argument(EG(zend_constants), clean_module_constant, (void *) &module_number);
  80. }
  81. int zend_startup_constants(void)
  82. {
  83. EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
  84. zend_hash_init(EG(zend_constants), 128, NULL, ZEND_CONSTANT_DTOR, 1);
  85. return SUCCESS;
  86. }
  87. void zend_register_standard_constants(void)
  88. {
  89. REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
  90. REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
  91. REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
  92. REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
  93. REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
  94. REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
  95. REGISTER_MAIN_LONG_CONSTANT("E_DEPRECATED", E_DEPRECATED, CONST_PERSISTENT | CONST_CS);
  96. REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
  97. REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
  98. REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
  99. REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
  100. REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
  101. REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
  102. REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
  103. REGISTER_MAIN_LONG_CONSTANT("E_USER_DEPRECATED", E_USER_DEPRECATED, CONST_PERSISTENT | CONST_CS);
  104. REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
  105. REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_PROVIDE_OBJECT", DEBUG_BACKTRACE_PROVIDE_OBJECT, CONST_PERSISTENT | CONST_CS);
  106. REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_IGNORE_ARGS", DEBUG_BACKTRACE_IGNORE_ARGS, CONST_PERSISTENT | CONST_CS);
  107. /* true/false constants */
  108. {
  109. REGISTER_MAIN_BOOL_CONSTANT("TRUE", 1, CONST_PERSISTENT | CONST_CT_SUBST);
  110. REGISTER_MAIN_BOOL_CONSTANT("FALSE", 0, CONST_PERSISTENT | CONST_CT_SUBST);
  111. REGISTER_MAIN_BOOL_CONSTANT("ZEND_THREAD_SAFE", ZTS_V, CONST_PERSISTENT | CONST_CS);
  112. REGISTER_MAIN_BOOL_CONSTANT("ZEND_DEBUG_BUILD", ZEND_DEBUG, CONST_PERSISTENT | CONST_CS);
  113. }
  114. REGISTER_MAIN_NULL_CONSTANT("NULL", CONST_PERSISTENT | CONST_CT_SUBST);
  115. }
  116. int zend_shutdown_constants(void)
  117. {
  118. zend_hash_destroy(EG(zend_constants));
  119. free(EG(zend_constants));
  120. return SUCCESS;
  121. }
  122. ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number)
  123. {
  124. zend_constant c;
  125. ZVAL_NULL(&c.value);
  126. ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
  127. c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
  128. zend_register_constant(&c);
  129. }
  130. ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, zend_bool bval, int flags, int module_number)
  131. {
  132. zend_constant c;
  133. ZVAL_BOOL(&c.value, bval);
  134. ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
  135. c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
  136. zend_register_constant(&c);
  137. }
  138. ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number)
  139. {
  140. zend_constant c;
  141. ZVAL_LONG(&c.value, lval);
  142. ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
  143. c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
  144. zend_register_constant(&c);
  145. }
  146. ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number)
  147. {
  148. zend_constant c;
  149. ZVAL_DOUBLE(&c.value, dval);
  150. ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
  151. c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
  152. zend_register_constant(&c);
  153. }
  154. ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, char *strval, size_t strlen, int flags, int module_number)
  155. {
  156. zend_constant c;
  157. ZVAL_STR(&c.value, zend_string_init_interned(strval, strlen, flags & CONST_PERSISTENT));
  158. ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
  159. c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
  160. zend_register_constant(&c);
  161. }
  162. ZEND_API void zend_register_string_constant(const char *name, size_t name_len, char *strval, int flags, int module_number)
  163. {
  164. zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number);
  165. }
  166. static zend_constant *zend_get_special_constant(const char *name, size_t name_len)
  167. {
  168. zend_constant *c;
  169. static const char haltoff[] = "__COMPILER_HALT_OFFSET__";
  170. if (!EG(current_execute_data)) {
  171. return NULL;
  172. } else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
  173. !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
  174. const char *cfilename;
  175. zend_string *haltname;
  176. size_t clen;
  177. cfilename = zend_get_executed_filename();
  178. clen = strlen(cfilename);
  179. /* check for __COMPILER_HALT_OFFSET__ */
  180. haltname = zend_mangle_property_name(haltoff,
  181. sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
  182. c = zend_hash_find_ptr(EG(zend_constants), haltname);
  183. zend_string_efree(haltname);
  184. return c;
  185. } else {
  186. return NULL;
  187. }
  188. }
  189. ZEND_API int zend_verify_const_access(zend_class_constant *c, zend_class_entry *scope) /* {{{ */
  190. {
  191. if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PUBLIC) {
  192. return 1;
  193. } else if (Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PRIVATE) {
  194. return (c->ce == scope);
  195. } else {
  196. ZEND_ASSERT(Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PROTECTED);
  197. return zend_check_protected(c->ce, scope);
  198. }
  199. }
  200. /* }}} */
  201. static inline zend_constant *zend_get_constant_str_impl(const char *name, size_t name_len)
  202. {
  203. zend_constant *c;
  204. ALLOCA_FLAG(use_heap)
  205. if ((c = zend_hash_str_find_ptr(EG(zend_constants), name, name_len)) == NULL) {
  206. char *lcname = do_alloca(name_len + 1, use_heap);
  207. zend_str_tolower_copy(lcname, name, name_len);
  208. if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, name_len)) != NULL) {
  209. if (ZEND_CONSTANT_FLAGS(c) & CONST_CS) {
  210. c = NULL;
  211. }
  212. } else {
  213. c = zend_get_special_constant(name, name_len);
  214. }
  215. free_alloca(lcname, use_heap);
  216. }
  217. return c;
  218. }
  219. ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len)
  220. {
  221. zend_constant *c = zend_get_constant_str_impl(name, name_len);
  222. return c ? &c->value : NULL;
  223. }
  224. static inline zend_constant *zend_get_constant_impl(zend_string *name)
  225. {
  226. zval *zv;
  227. zend_constant *c;
  228. ALLOCA_FLAG(use_heap)
  229. zv = zend_hash_find(EG(zend_constants), name);
  230. if (zv == NULL) {
  231. char *lcname = do_alloca(ZSTR_LEN(name) + 1, use_heap);
  232. zend_str_tolower_copy(lcname, ZSTR_VAL(name), ZSTR_LEN(name));
  233. zv = zend_hash_str_find(EG(zend_constants), lcname, ZSTR_LEN(name));
  234. if (zv != NULL) {
  235. c = Z_PTR_P(zv);
  236. if (ZEND_CONSTANT_FLAGS(c) & CONST_CS) {
  237. c = NULL;
  238. }
  239. } else {
  240. c = zend_get_special_constant(ZSTR_VAL(name), ZSTR_LEN(name));
  241. }
  242. free_alloca(lcname, use_heap);
  243. return c;
  244. } else {
  245. return (zend_constant *) Z_PTR_P(zv);
  246. }
  247. }
  248. ZEND_API zval *zend_get_constant(zend_string *name)
  249. {
  250. zend_constant *c = zend_get_constant_impl(name);
  251. return c ? &c->value : NULL;
  252. }
  253. static zend_bool is_access_deprecated(const zend_constant *c, const char *access_name) {
  254. const char *ns_sep = zend_memrchr(ZSTR_VAL(c->name), '\\', ZSTR_LEN(c->name));
  255. if (ns_sep) {
  256. /* Namespaces are always case-insensitive. Only compare shortname. */
  257. size_t shortname_offset = ns_sep - ZSTR_VAL(c->name) + 1;
  258. size_t shortname_len = ZSTR_LEN(c->name) - shortname_offset;
  259. return memcmp(
  260. access_name + shortname_offset,
  261. ZSTR_VAL(c->name) + shortname_offset,
  262. shortname_len
  263. ) != 0;
  264. } else {
  265. /* No namespace, compare whole name */
  266. return memcmp(access_name, ZSTR_VAL(c->name), ZSTR_LEN(c->name)) != 0;
  267. }
  268. }
  269. ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, uint32_t flags)
  270. {
  271. zend_constant *c;
  272. const char *colon;
  273. zend_class_entry *ce = NULL;
  274. const char *name = ZSTR_VAL(cname);
  275. size_t name_len = ZSTR_LEN(cname);
  276. /* Skip leading \\ */
  277. if (name[0] == '\\') {
  278. name += 1;
  279. name_len -= 1;
  280. cname = NULL;
  281. }
  282. if ((colon = zend_memrchr(name, ':', name_len)) &&
  283. colon > name && (*(colon - 1) == ':')) {
  284. int class_name_len = colon - name - 1;
  285. size_t const_name_len = name_len - class_name_len - 2;
  286. zend_string *constant_name = zend_string_init(colon + 1, const_name_len, 0);
  287. zend_string *class_name = zend_string_init(name, class_name_len, 0);
  288. zend_class_constant *c = NULL;
  289. zval *ret_constant = NULL;
  290. if (zend_string_equals_literal_ci(class_name, "self")) {
  291. if (UNEXPECTED(!scope)) {
  292. zend_throw_error(NULL, "Cannot access self:: when no class scope is active");
  293. goto failure;
  294. }
  295. ce = scope;
  296. } else if (zend_string_equals_literal_ci(class_name, "parent")) {
  297. if (UNEXPECTED(!scope)) {
  298. zend_throw_error(NULL, "Cannot access parent:: when no class scope is active");
  299. goto failure;
  300. } else if (UNEXPECTED(!scope->parent)) {
  301. zend_throw_error(NULL, "Cannot access parent:: when current class scope has no parent");
  302. goto failure;
  303. } else {
  304. ce = scope->parent;
  305. }
  306. } else if (zend_string_equals_literal_ci(class_name, "static")) {
  307. ce = zend_get_called_scope(EG(current_execute_data));
  308. if (UNEXPECTED(!ce)) {
  309. zend_throw_error(NULL, "Cannot access static:: when no class scope is active");
  310. goto failure;
  311. }
  312. } else {
  313. ce = zend_fetch_class(class_name, flags);
  314. }
  315. if (ce) {
  316. c = zend_hash_find_ptr(&ce->constants_table, constant_name);
  317. if (c == NULL) {
  318. if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
  319. zend_throw_error(NULL, "Undefined class constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
  320. goto failure;
  321. }
  322. ret_constant = NULL;
  323. } else {
  324. if (!zend_verify_const_access(c, scope)) {
  325. if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
  326. zend_throw_error(NULL, "Cannot access %s const %s::%s", zend_visibility_string(Z_ACCESS_FLAGS(c->value)), ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
  327. }
  328. goto failure;
  329. }
  330. ret_constant = &c->value;
  331. }
  332. }
  333. if (ret_constant && Z_TYPE_P(ret_constant) == IS_CONSTANT_AST) {
  334. int ret;
  335. if (IS_CONSTANT_VISITED(ret_constant)) {
  336. zend_throw_error(NULL, "Cannot declare self-referencing constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
  337. ret_constant = NULL;
  338. goto failure;
  339. }
  340. MARK_CONSTANT_VISITED(ret_constant);
  341. ret = zval_update_constant_ex(ret_constant, c->ce);
  342. RESET_CONSTANT_VISITED(ret_constant);
  343. if (UNEXPECTED(ret != SUCCESS)) {
  344. ret_constant = NULL;
  345. goto failure;
  346. }
  347. }
  348. failure:
  349. zend_string_release_ex(class_name, 0);
  350. zend_string_efree(constant_name);
  351. return ret_constant;
  352. }
  353. /* non-class constant */
  354. if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
  355. /* compound constant name */
  356. int prefix_len = colon - name;
  357. size_t const_name_len = name_len - prefix_len - 1;
  358. const char *constant_name = colon + 1;
  359. char *lcname;
  360. size_t lcname_len;
  361. ALLOCA_FLAG(use_heap)
  362. lcname_len = prefix_len + 1 + const_name_len;
  363. lcname = do_alloca(lcname_len + 1, use_heap);
  364. zend_str_tolower_copy(lcname, name, prefix_len);
  365. /* Check for namespace constant */
  366. lcname[prefix_len] = '\\';
  367. memcpy(lcname + prefix_len + 1, constant_name, const_name_len + 1);
  368. if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, lcname_len)) == NULL) {
  369. /* try lowercase */
  370. zend_str_tolower(lcname + prefix_len + 1, const_name_len);
  371. if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, lcname_len)) != NULL) {
  372. if ((ZEND_CONSTANT_FLAGS(c) & CONST_CS) != 0) {
  373. c = NULL;
  374. }
  375. }
  376. }
  377. free_alloca(lcname, use_heap);
  378. if (!c) {
  379. if (!(flags & IS_CONSTANT_UNQUALIFIED)) {
  380. return NULL;
  381. }
  382. /* name requires runtime resolution, need to check non-namespaced name */
  383. c = zend_get_constant_str_impl(constant_name, const_name_len);
  384. name = constant_name;
  385. }
  386. } else {
  387. if (cname) {
  388. c = zend_get_constant_impl(cname);
  389. } else {
  390. c = zend_get_constant_str_impl(name, name_len);
  391. }
  392. }
  393. if (!c) {
  394. return NULL;
  395. }
  396. if (!(flags & ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK)) {
  397. if (!(ZEND_CONSTANT_FLAGS(c) & (CONST_CS|CONST_CT_SUBST)) && is_access_deprecated(c, name)) {
  398. zend_error(E_DEPRECATED,
  399. "Case-insensitive constants are deprecated. "
  400. "The correct casing for this constant is \"%s\"",
  401. ZSTR_VAL(c->name));
  402. }
  403. }
  404. return &c->value;
  405. }
  406. static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
  407. {
  408. void *ret;
  409. zend_constant *copy = pemalloc(sizeof(zend_constant), ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
  410. memcpy(copy, c, sizeof(zend_constant));
  411. ret = zend_hash_add_ptr(ht, key, copy);
  412. if (!ret) {
  413. pefree(copy, ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
  414. }
  415. return ret;
  416. }
  417. ZEND_API int zend_register_constant(zend_constant *c)
  418. {
  419. zend_string *lowercase_name = NULL;
  420. zend_string *name;
  421. int ret = SUCCESS;
  422. #if 0
  423. printf("Registering constant for module %d\n", c->module_number);
  424. #endif
  425. if (!(ZEND_CONSTANT_FLAGS(c) & CONST_CS)) {
  426. lowercase_name = zend_string_tolower_ex(c->name, ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
  427. lowercase_name = zend_new_interned_string(lowercase_name);
  428. name = lowercase_name;
  429. } else {
  430. char *slash = strrchr(ZSTR_VAL(c->name), '\\');
  431. if (slash) {
  432. lowercase_name = zend_string_init(ZSTR_VAL(c->name), ZSTR_LEN(c->name), ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
  433. zend_str_tolower(ZSTR_VAL(lowercase_name), slash - ZSTR_VAL(c->name));
  434. lowercase_name = zend_new_interned_string(lowercase_name);
  435. name = lowercase_name;
  436. } else {
  437. name = c->name;
  438. }
  439. }
  440. /* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
  441. if (zend_string_equals_literal(name, "__COMPILER_HALT_OFFSET__")
  442. || zend_hash_add_constant(EG(zend_constants), name, c) == NULL) {
  443. /* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
  444. if (ZSTR_VAL(c->name)[0] == '\0' && ZSTR_LEN(c->name) > sizeof("\0__COMPILER_HALT_OFFSET__")-1
  445. && memcmp(ZSTR_VAL(name), "\0__COMPILER_HALT_OFFSET__", sizeof("\0__COMPILER_HALT_OFFSET__")) == 0) {
  446. }
  447. zend_error(E_NOTICE,"Constant %s already defined", ZSTR_VAL(name));
  448. zend_string_release(c->name);
  449. if (!(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)) {
  450. zval_ptr_dtor_nogc(&c->value);
  451. }
  452. ret = FAILURE;
  453. }
  454. if (lowercase_name) {
  455. zend_string_release(lowercase_name);
  456. }
  457. return ret;
  458. }
  459. /*
  460. * Local variables:
  461. * tab-width: 4
  462. * c-basic-offset: 4
  463. * indent-tabs-mode: t
  464. * End:
  465. * vim600: sw=4 ts=4 fdm=marker
  466. * vim<600: sw=4 ts=4
  467. */