xref: /PHP-5.6/Zend/zend_constants.c (revision 3537e95d)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2016 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@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #include "zend.h"
23 #include "zend_constants.h"
24 #include "zend_execute.h"
25 #include "zend_variables.h"
26 #include "zend_operators.h"
27 #include "zend_globals.h"
28 #include "zend_API.h"
29 
free_zend_constant(zend_constant * c)30 void free_zend_constant(zend_constant *c)
31 {
32 	if (!(c->flags & CONST_PERSISTENT)) {
33 		zval_dtor(&c->value);
34 	}
35 	str_free(c->name);
36 }
37 
38 
copy_zend_constant(zend_constant * c)39 void copy_zend_constant(zend_constant *c)
40 {
41 	c->name = str_strndup(c->name, c->name_len - 1);
42 	if (!(c->flags & CONST_PERSISTENT)) {
43 		zval_copy_ctor(&c->value);
44 	}
45 }
46 
47 
zend_copy_constants(HashTable * target,HashTable * source)48 void zend_copy_constants(HashTable *target, HashTable *source)
49 {
50 	zend_constant tmp_constant;
51 
52 	zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant));
53 }
54 
55 
clean_non_persistent_constant(const zend_constant * c TSRMLS_DC)56 static int clean_non_persistent_constant(const zend_constant *c TSRMLS_DC)
57 {
58 	return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
59 }
60 
61 
clean_non_persistent_constant_full(const zend_constant * c TSRMLS_DC)62 static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC)
63 {
64 	return (c->flags & CONST_PERSISTENT) ? 0 : 1;
65 }
66 
67 
clean_module_constant(const zend_constant * c,int * module_number TSRMLS_DC)68 static int clean_module_constant(const zend_constant *c, int *module_number TSRMLS_DC)
69 {
70 	if (c->module_number == *module_number) {
71 		return 1;
72 	} else {
73 		return 0;
74 	}
75 }
76 
77 
clean_module_constants(int module_number TSRMLS_DC)78 void clean_module_constants(int module_number TSRMLS_DC)
79 {
80 	zend_hash_apply_with_argument(EG(zend_constants), (apply_func_arg_t) clean_module_constant, (void *) &module_number TSRMLS_CC);
81 }
82 
83 
zend_startup_constants(TSRMLS_D)84 int zend_startup_constants(TSRMLS_D)
85 {
86 	EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
87 
88 	if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
89 		return FAILURE;
90 	}
91 	return SUCCESS;
92 }
93 
94 
95 
zend_register_standard_constants(TSRMLS_D)96 void zend_register_standard_constants(TSRMLS_D)
97 {
98 	REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
99 	REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
100 	REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
101 	REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
102 	REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
103 	REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
104 	REGISTER_MAIN_LONG_CONSTANT("E_DEPRECATED", E_DEPRECATED, CONST_PERSISTENT | CONST_CS);
105 	REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
106 	REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
107 	REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
108 	REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
109 	REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
110 	REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
111 	REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
112 	REGISTER_MAIN_LONG_CONSTANT("E_USER_DEPRECATED", E_USER_DEPRECATED, CONST_PERSISTENT | CONST_CS);
113 
114 	REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
115 
116 	REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_PROVIDE_OBJECT", DEBUG_BACKTRACE_PROVIDE_OBJECT, CONST_PERSISTENT | CONST_CS);
117 	REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_IGNORE_ARGS", DEBUG_BACKTRACE_IGNORE_ARGS, CONST_PERSISTENT | CONST_CS);
118 	/* true/false constants */
119 	{
120 		REGISTER_MAIN_BOOL_CONSTANT("TRUE", 1, CONST_PERSISTENT | CONST_CT_SUBST);
121 		REGISTER_MAIN_BOOL_CONSTANT("FALSE", 0, CONST_PERSISTENT | CONST_CT_SUBST);
122 		REGISTER_MAIN_BOOL_CONSTANT("ZEND_THREAD_SAFE", ZTS_V, CONST_PERSISTENT | CONST_CS);
123 		REGISTER_MAIN_BOOL_CONSTANT("ZEND_DEBUG_BUILD", ZEND_DEBUG, CONST_PERSISTENT | CONST_CS);
124 	}
125 	REGISTER_MAIN_NULL_CONSTANT("NULL", CONST_PERSISTENT | CONST_CT_SUBST);
126 }
127 
128 
zend_shutdown_constants(TSRMLS_D)129 int zend_shutdown_constants(TSRMLS_D)
130 {
131 	zend_hash_destroy(EG(zend_constants));
132 	free(EG(zend_constants));
133 	return SUCCESS;
134 }
135 
136 
clean_non_persistent_constants(TSRMLS_D)137 void clean_non_persistent_constants(TSRMLS_D)
138 {
139 	if (EG(full_tables_cleanup)) {
140 		zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
141 	} else {
142 		zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
143 	}
144 }
145 
zend_register_null_constant(const char * name,uint name_len,int flags,int module_number TSRMLS_DC)146 ZEND_API void zend_register_null_constant(const char *name, uint name_len, int flags, int module_number TSRMLS_DC)
147 {
148 	zend_constant c;
149 
150 	ZVAL_NULL(&c.value);
151 	c.flags = flags;
152 	c.name = zend_strndup(name, name_len-1);
153 	c.name_len = name_len;
154 	c.module_number = module_number;
155 	zend_register_constant(&c TSRMLS_CC);
156 }
157 
zend_register_bool_constant(const char * name,uint name_len,zend_bool bval,int flags,int module_number TSRMLS_DC)158 ZEND_API void zend_register_bool_constant(const char *name, uint name_len, zend_bool bval, int flags, int module_number TSRMLS_DC)
159 {
160 	zend_constant c;
161 
162 	ZVAL_BOOL(&c.value, bval);
163 	c.flags = flags;
164 	c.name = zend_strndup(name, name_len-1);
165 	c.name_len = name_len;
166 	c.module_number = module_number;
167 	zend_register_constant(&c TSRMLS_CC);
168 }
169 
zend_register_long_constant(const char * name,uint name_len,long lval,int flags,int module_number TSRMLS_DC)170 ZEND_API void zend_register_long_constant(const char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC)
171 {
172 	zend_constant c;
173 
174 	ZVAL_LONG(&c.value, lval);
175 	c.flags = flags;
176 	c.name = zend_strndup(name, name_len-1);
177 	c.name_len = name_len;
178 	c.module_number = module_number;
179 	zend_register_constant(&c TSRMLS_CC);
180 }
181 
182 
zend_register_double_constant(const char * name,uint name_len,double dval,int flags,int module_number TSRMLS_DC)183 ZEND_API void zend_register_double_constant(const char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC)
184 {
185 	zend_constant c;
186 
187 	ZVAL_DOUBLE(&c.value, dval);
188 	c.flags = flags;
189 	c.name = zend_strndup(name, name_len-1);
190 	c.name_len = name_len;
191 	c.module_number = module_number;
192 	zend_register_constant(&c TSRMLS_CC);
193 }
194 
195 
zend_register_stringl_constant(const char * name,uint name_len,char * strval,uint strlen,int flags,int module_number TSRMLS_DC)196 ZEND_API void zend_register_stringl_constant(const char *name, uint name_len, char *strval, uint strlen, int flags, int module_number TSRMLS_DC)
197 {
198 	zend_constant c;
199 
200 	ZVAL_STRINGL(&c.value, strval, strlen, 0);
201 	c.flags = flags;
202 	c.name = zend_strndup(name, name_len-1);
203 	c.name_len = name_len;
204 	c.module_number = module_number;
205 	zend_register_constant(&c TSRMLS_CC);
206 }
207 
208 
zend_register_string_constant(const char * name,uint name_len,char * strval,int flags,int module_number TSRMLS_DC)209 ZEND_API void zend_register_string_constant(const char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC)
210 {
211 	zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number TSRMLS_CC);
212 }
213 
zend_get_special_constant(const char * name,uint name_len,zend_constant ** c TSRMLS_DC)214 static int zend_get_special_constant(const char *name, uint name_len, zend_constant **c TSRMLS_DC)
215 {
216 	int ret;
217 	static char haltoff[] = "__COMPILER_HALT_OFFSET__";
218 
219 	if (!EG(in_execution)) {
220 		return 0;
221 	} else if (name_len == sizeof("__CLASS__")-1 &&
222 	          !memcmp(name, "__CLASS__", sizeof("__CLASS__")-1)) {
223 		zend_constant tmp;
224 
225 		/* Returned constants may be cached, so they have to be stored */
226 		if (EG(scope) && EG(scope)->name) {
227 			int const_name_len;
228 			char *const_name;
229 			ALLOCA_FLAG(use_heap)
230 
231 			const_name_len = sizeof("\0__CLASS__") + EG(scope)->name_length;
232 			const_name = do_alloca(const_name_len, use_heap);
233 			memcpy(const_name, "\0__CLASS__", sizeof("\0__CLASS__")-1);
234 			zend_str_tolower_copy(const_name + sizeof("\0__CLASS__")-1, EG(scope)->name, EG(scope)->name_length);
235 			if (zend_hash_find(EG(zend_constants), const_name, const_name_len, (void**)c) == FAILURE) {
236 				zend_hash_add(EG(zend_constants), const_name, const_name_len, (void*)&tmp, sizeof(zend_constant), (void**)c);
237 				memset(*c, 0, sizeof(zend_constant));
238 				Z_STRVAL((**c).value) = estrndup(EG(scope)->name, EG(scope)->name_length);
239 				Z_STRLEN((**c).value) = EG(scope)->name_length;
240 				Z_TYPE((**c).value) = IS_STRING;
241 			}
242 			free_alloca(const_name, use_heap);
243 		} else {
244 			if (zend_hash_find(EG(zend_constants), "\0__CLASS__", sizeof("\0__CLASS__"), (void**)c) == FAILURE) {
245 				zend_hash_add(EG(zend_constants), "\0__CLASS__", sizeof("\0__CLASS__"), (void*)&tmp, sizeof(zend_constant), (void**)c);
246 				memset(*c, 0, sizeof(zend_constant));
247 				Z_STRVAL((**c).value) = estrndup("", 0);
248 				Z_STRLEN((**c).value) = 0;
249 				Z_TYPE((**c).value) = IS_STRING;
250 			}
251 		}
252 		return 1;
253 	} else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
254 	          !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
255 		const char *cfilename;
256 		char *haltname;
257 		int len, clen;
258 
259 		cfilename = zend_get_executed_filename(TSRMLS_C);
260 		clen = strlen(cfilename);
261 		/* check for __COMPILER_HALT_OFFSET__ */
262 		zend_mangle_property_name(&haltname, &len, haltoff,
263 			sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
264 		ret = zend_hash_find(EG(zend_constants), haltname, len+1, (void **) c);
265 		efree(haltname);
266 		return (ret == SUCCESS);
267 	} else {
268 		return 0;
269 	}
270 }
271 
272 
zend_get_constant(const char * name,uint name_len,zval * result TSRMLS_DC)273 ZEND_API int zend_get_constant(const char *name, uint name_len, zval *result TSRMLS_DC)
274 {
275 	zend_constant *c;
276 	int retval = 1;
277 	char *lookup_name;
278 
279 	if (zend_hash_find(EG(zend_constants), name, name_len+1, (void **) &c) == FAILURE) {
280 		lookup_name = zend_str_tolower_dup(name, name_len);
281 
282 		if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
283 			if (c->flags & CONST_CS) {
284 				retval=0;
285 			}
286 		} else {
287 			retval = zend_get_special_constant(name, name_len, &c TSRMLS_CC);
288 		}
289 		efree(lookup_name);
290 	}
291 
292 	if (retval) {
293 		*result = c->value;
294 		zval_copy_ctor(result);
295 		Z_SET_REFCOUNT_P(result, 1);
296 		Z_UNSET_ISREF_P(result);
297 	}
298 
299 	return retval;
300 }
301 
zend_get_constant_ex(const char * name,uint name_len,zval * result,zend_class_entry * scope,ulong flags TSRMLS_DC)302 ZEND_API int zend_get_constant_ex(const char *name, uint name_len, zval *result, zend_class_entry *scope, ulong flags TSRMLS_DC)
303 {
304 	zend_constant *c;
305 	int retval = 1;
306 	const char *colon;
307 	zend_class_entry *ce = NULL;
308 	char *class_name;
309 	zval **ret_constant;
310 
311 	/* Skip leading \\ */
312 	if (name[0] == '\\') {
313 		name += 1;
314 		name_len -= 1;
315 	}
316 
317 
318 	if ((colon = zend_memrchr(name, ':', name_len)) &&
319 	    colon > name && (*(colon - 1) == ':')) {
320 		int class_name_len = colon - name - 1;
321 		int const_name_len = name_len - class_name_len - 2;
322 		const char *constant_name = colon + 1;
323 		char *lcname;
324 
325 		class_name = estrndup(name, class_name_len);
326 		lcname = zend_str_tolower_dup(class_name, class_name_len);
327 		if (!scope) {
328 			if (EG(in_execution)) {
329 				scope = EG(scope);
330 			} else {
331 				scope = CG(active_class_entry);
332 			}
333 		}
334 
335 		if (class_name_len == sizeof("self")-1 &&
336 		    !memcmp(lcname, "self", sizeof("self")-1)) {
337 			if (scope) {
338 				ce = scope;
339 			} else {
340 				zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
341 				retval = 0;
342 			}
343 			efree(lcname);
344 		} else if (class_name_len == sizeof("parent")-1 &&
345 		           !memcmp(lcname, "parent", sizeof("parent")-1)) {
346 			if (!scope) {
347 				zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
348 			} else if (!scope->parent) {
349 				zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
350 			} else {
351 				ce = scope->parent;
352 			}
353 			efree(lcname);
354 		} else if (class_name_len == sizeof("static")-1 &&
355 		           !memcmp(lcname, "static", sizeof("static")-1)) {
356 			if (EG(called_scope)) {
357 				ce = EG(called_scope);
358 			} else {
359 				zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
360 			}
361 			efree(lcname);
362 		} else {
363 			efree(lcname);
364 			ce = zend_fetch_class(class_name, class_name_len, flags TSRMLS_CC);
365 		}
366 		if (retval && ce) {
367 			if (zend_hash_find(&ce->constants_table, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
368 				retval = 0;
369 				if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
370 					zend_error(E_ERROR, "Undefined class constant '%s::%s'", class_name, constant_name);
371 				}
372 			}
373 		} else if (!ce) {
374 			retval = 0;
375 		}
376 		efree(class_name);
377 		goto finish;
378 	}
379 
380 	/* non-class constant */
381 	if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
382 		/* compound constant name */
383 		int prefix_len = colon - name;
384 		int const_name_len = name_len - prefix_len - 1;
385 		const char *constant_name = colon + 1;
386 		char *lcname;
387 		int found_const = 0;
388 
389 		lcname = zend_str_tolower_dup(name, prefix_len);
390 		/* Check for namespace constant */
391 
392 		/* Concatenate lowercase namespace name and constant name */
393 		lcname = erealloc(lcname, prefix_len + 1 + const_name_len + 1);
394 		lcname[prefix_len] = '\\';
395 		memcpy(lcname + prefix_len + 1, constant_name, const_name_len + 1);
396 
397 		if (zend_hash_find(EG(zend_constants), lcname, prefix_len + 1 + const_name_len + 1, (void **) &c) == SUCCESS) {
398 			found_const = 1;
399 		} else {
400 			/* try lowercase */
401 			zend_str_tolower(lcname + prefix_len + 1, const_name_len);
402 			if (zend_hash_find(EG(zend_constants), lcname, prefix_len + 1 + const_name_len + 1, (void **) &c) == SUCCESS) {
403 				if ((c->flags & CONST_CS) == 0) {
404 					found_const = 1;
405 				}
406 			}
407 		}
408 		efree(lcname);
409 		if(found_const) {
410 			*result = c->value;
411 			zval_update_constant_ex(&result, 1, NULL TSRMLS_CC);
412 			zval_copy_ctor(result);
413 			Z_SET_REFCOUNT_P(result, 1);
414 			Z_UNSET_ISREF_P(result);
415 			return 1;
416 		}
417 		/* name requires runtime resolution, need to check non-namespaced name */
418 		if ((flags & IS_CONSTANT_UNQUALIFIED) != 0) {
419 			name = constant_name;
420 			name_len = const_name_len;
421 			return zend_get_constant(name, name_len, result TSRMLS_CC);
422 		}
423 		retval = 0;
424 finish:
425 		if (retval) {
426 			zval_update_constant_ex(ret_constant, 1, ce TSRMLS_CC);
427 			*result = **ret_constant;
428 			zval_copy_ctor(result);
429 			INIT_PZVAL(result);
430 		}
431 
432 		return retval;
433 	}
434 
435 	return zend_get_constant(name, name_len, result TSRMLS_CC);
436 }
437 
zend_quick_get_constant(const zend_literal * key,ulong flags TSRMLS_DC)438 zend_constant *zend_quick_get_constant(const zend_literal *key, ulong flags TSRMLS_DC)
439 {
440 	zend_constant *c;
441 
442 	if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE) {
443 		key++;
444 		if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE ||
445 		    (c->flags & CONST_CS) != 0) {
446 			if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
447 				key++;
448 				if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE) {
449 				    key++;
450 					if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE ||
451 					    (c->flags & CONST_CS) != 0) {
452 
453 						key--;
454 						if (!zend_get_special_constant(Z_STRVAL(key->constant), Z_STRLEN(key->constant), &c TSRMLS_CC)) {
455 							return NULL;
456 						}
457 					}
458 				}
459 			} else {
460 				key--;
461 				if (!zend_get_special_constant(Z_STRVAL(key->constant), Z_STRLEN(key->constant), &c TSRMLS_CC)) {
462 					return NULL;
463 				}
464 			}
465 		}
466 	}
467 	return c;
468 }
469 
zend_register_constant(zend_constant * c TSRMLS_DC)470 ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
471 {
472 	char *lowercase_name = NULL;
473 	char *name;
474 	int ret = SUCCESS;
475 	ulong chash;
476 
477 #if 0
478 	printf("Registering constant for module %d\n", c->module_number);
479 #endif
480 
481 	if (!(c->flags & CONST_CS)) {
482 		/* keep in mind that c->name_len already contains the '\0' */
483 		lowercase_name = estrndup(c->name, c->name_len-1);
484 		zend_str_tolower(lowercase_name, c->name_len-1);
485 		lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
486 		name = lowercase_name;
487 	} else {
488 		char *slash = strrchr(c->name, '\\');
489 		if (slash) {
490 			lowercase_name = estrndup(c->name, c->name_len-1);
491 			zend_str_tolower(lowercase_name, slash-c->name);
492 			lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
493 			name = lowercase_name;
494 		} else {
495 			name = c->name;
496 		}
497 	}
498 	chash = str_hash(name, c->name_len-1);
499 
500 	/* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
501 	if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__")
502 		&& !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
503 		|| zend_hash_quick_add(EG(zend_constants), name, c->name_len, chash, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
504 
505 		/* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
506 		if (c->name[0] == '\0' && c->name_len > sizeof("\0__COMPILER_HALT_OFFSET__")
507 			&& memcmp(name, "\0__COMPILER_HALT_OFFSET__", sizeof("\0__COMPILER_HALT_OFFSET__")) == 0) {
508 			name++;
509 		}
510 		zend_error(E_NOTICE,"Constant %s already defined", name);
511 		str_free(c->name);
512 		if (!(c->flags & CONST_PERSISTENT)) {
513 			zval_dtor(&c->value);
514 		}
515 		ret = FAILURE;
516 	}
517 	if (lowercase_name) {
518 		str_efree(lowercase_name);
519 	}
520 	return ret;
521 }
522 
523 
524 /*
525  * Local variables:
526  * tab-width: 4
527  * c-basic-offset: 4
528  * indent-tabs-mode: t
529  * End:
530  */
531