1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2007-01-01 17:36:18 +08:00
|
|
|
| Copyright (c) 1998-2007 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
1999-07-16 22:58:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 22:58:16 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 09:49:15 +08:00
|
|
|
/* $Id$ */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_constants.h"
|
2003-06-15 23:34:00 +08:00
|
|
|
#include "zend_execute.h"
|
1999-04-08 02:10:10 +08:00
|
|
|
#include "zend_variables.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
|
|
|
|
2000-01-18 01:33:37 +08:00
|
|
|
void free_zend_constant(zend_constant *c)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2002-06-22 21:52:07 +08:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(&c->value);
|
|
|
|
}
|
|
|
|
free(c->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-15 00:00:47 +08:00
|
|
|
void copy_zend_constant(zend_constant *c)
|
|
|
|
{
|
2003-12-12 08:16:58 +08:00
|
|
|
c->name = zend_strndup(c->name, c->name_len - 1);
|
2000-02-14 06:15:06 +08:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
|
|
|
zval_copy_ctor(&c->value);
|
|
|
|
}
|
1999-07-15 00:00:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zend_copy_constants(HashTable *target, HashTable *source)
|
|
|
|
{
|
|
|
|
zend_constant tmp_constant;
|
|
|
|
|
2000-02-05 23:11:24 +08:00
|
|
|
zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant));
|
1999-07-15 00:00:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
static int clean_non_persistent_constant(zend_constant *c TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2006-03-13 19:13:42 +08:00
|
|
|
return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int clean_non_persistent_constant_full(zend_constant *c TSRMLS_DC)
|
|
|
|
{
|
2006-03-14 19:24:45 +08:00
|
|
|
return (c->flags & CONST_PERSISTENT) ? 0 : 1;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
static int clean_module_constant(zend_constant *c, int *module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
if (c->module_number == *module_number) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-30 15:43:02 +08:00
|
|
|
void clean_module_constants(int module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-31 12:53:54 +08:00
|
|
|
zend_hash_apply_with_argument(EG(zend_constants), (apply_func_arg_t) clean_module_constant, (void *) &module_number TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
int zend_startup_constants(TSRMLS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2003-06-02 20:13:11 +08:00
|
|
|
EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-07-15 00:00:47 +08:00
|
|
|
if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
void zend_register_standard_constants(TSRMLS_D)
|
1999-07-15 00:00:47 +08:00
|
|
|
{
|
1999-04-08 02:10:10 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
|
2006-05-10 22:04:18 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
|
1999-04-08 02:10:10 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
|
1999-07-23 06:17:49 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
|
2003-11-18 17:25:04 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
|
1999-07-23 06:17:49 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
|
2000-04-19 21:15:13 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
|
1999-07-23 06:17:49 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
|
|
|
|
|
|
|
|
/* true/false constants */
|
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
2006-03-15 17:04:36 +08:00
|
|
|
c.flags = CONST_PERSISTENT | CONST_CT_SUBST;
|
1999-04-08 02:10:10 +08:00
|
|
|
c.module_number = 0;
|
|
|
|
|
2005-01-20 10:02:09 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("TRUE"));
|
1999-12-31 21:56:59 +08:00
|
|
|
c.name_len = sizeof("TRUE");
|
1999-04-08 02:10:10 +08:00
|
|
|
c.value.value.lval = 1;
|
|
|
|
c.value.type = IS_BOOL;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2005-01-20 10:02:09 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("FALSE"));
|
1999-12-31 21:56:59 +08:00
|
|
|
c.name_len = sizeof("FALSE");
|
1999-04-08 02:10:10 +08:00
|
|
|
c.value.value.lval = 0;
|
|
|
|
c.value.type = IS_BOOL;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-12-28 20:05:48 +08:00
|
|
|
|
2006-03-15 17:04:36 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("NULL"));
|
|
|
|
c.name_len = sizeof("NULL");
|
|
|
|
c.value.type = IS_NULL;
|
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
|
|
|
|
|
|
|
c.flags = CONST_PERSISTENT;
|
|
|
|
|
2005-01-20 10:02:09 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE"));
|
2000-06-27 02:15:33 +08:00
|
|
|
c.name_len = sizeof("ZEND_THREAD_SAFE");
|
|
|
|
c.value.value.lval = ZTS_V;
|
|
|
|
c.value.type = IS_BOOL;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
int zend_shutdown_constants(TSRMLS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_hash_destroy(EG(zend_constants));
|
2003-06-02 20:13:11 +08:00
|
|
|
free(EG(zend_constants));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-30 15:43:02 +08:00
|
|
|
void clean_non_persistent_constants(TSRMLS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-10-23 09:23:36 +08:00
|
|
|
if (EG(full_tables_cleanup)) {
|
2006-03-13 19:13:42 +08:00
|
|
|
zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
|
2001-10-23 09:23:36 +08:00
|
|
|
} else {
|
|
|
|
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_LONG;
|
|
|
|
c.value.value.lval = lval;
|
|
|
|
c.flags = flags;
|
2003-12-09 16:56:04 +08:00
|
|
|
c.name = zend_strndup(name, name_len-1);
|
1999-04-08 02:10:10 +08:00
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_DOUBLE;
|
|
|
|
c.value.value.dval = dval;
|
|
|
|
c.flags = flags;
|
2003-12-09 16:56:04 +08:00
|
|
|
c.name = zend_strndup(name, name_len-1);
|
1999-04-08 02:10:10 +08:00
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_STRING;
|
|
|
|
c.value.value.str.val = strval;
|
|
|
|
c.value.value.str.len = strlen;
|
|
|
|
c.flags = flags;
|
2003-12-09 16:56:04 +08:00
|
|
|
c.name = zend_strndup(name, name_len-1);
|
1999-04-08 02:10:10 +08:00
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-29 03:52:53 +08:00
|
|
|
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant *c;
|
2002-06-19 12:13:12 +08:00
|
|
|
int retval = 1;
|
2003-11-25 02:13:29 +08:00
|
|
|
char *lookup_name;
|
2007-09-29 03:52:53 +08:00
|
|
|
|
|
|
|
if (zend_hash_find(EG(zend_constants), name, name_len+1, (void **) &c) == FAILURE) {
|
|
|
|
lookup_name = zend_str_tolower_dup(name, name_len);
|
|
|
|
|
|
|
|
if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
|
|
|
|
if ((c->flags & CONST_CS) && memcmp(c->name, name, name_len) != 0) {
|
|
|
|
retval=0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
static char haltoff[] = "__COMPILER_HALT_OFFSET__";
|
|
|
|
|
|
|
|
if (!EG(in_execution)) {
|
|
|
|
retval = 0;
|
|
|
|
} else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
|
|
|
|
!memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
|
|
|
|
char *cfilename, *haltname;
|
|
|
|
int len, clen;
|
|
|
|
|
|
|
|
cfilename = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
clen = strlen(cfilename);
|
|
|
|
/* check for __COMPILER_HALT_OFFSET__ */
|
|
|
|
zend_mangle_property_name(&haltname, &len, haltoff,
|
|
|
|
sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
|
|
|
|
if (zend_hash_find(EG(zend_constants), haltname, len+1, (void **) &c) == SUCCESS) {
|
|
|
|
retval = 1;
|
|
|
|
} else {
|
|
|
|
retval=0;
|
|
|
|
}
|
|
|
|
pefree(haltname, 0);
|
|
|
|
} else {
|
|
|
|
retval=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
efree(lookup_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval) {
|
|
|
|
*result = c->value;
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
result->refcount = 1;
|
|
|
|
result->is_ref = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_class_entry *scope, ulong flags TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_constant *c;
|
|
|
|
int retval = 1;
|
2003-06-15 21:58:50 +08:00
|
|
|
char *colon;
|
|
|
|
|
2007-09-29 03:52:53 +08:00
|
|
|
/* Skip leading :: */
|
|
|
|
if (name[0] == ':' && name[1] == ':') {
|
|
|
|
name += 2;
|
|
|
|
name_len -= 2;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((colon = zend_memrchr(name, ':', name_len)) &&
|
|
|
|
colon > name &&
|
|
|
|
*(colon-1) == ':') {
|
|
|
|
/* compound constant name */
|
|
|
|
zend_class_entry *ce = NULL;
|
|
|
|
int class_name_len = colon - name - 1;
|
2003-06-15 21:58:50 +08:00
|
|
|
int const_name_len = name_len - class_name_len - 2;
|
2007-09-29 03:52:53 +08:00
|
|
|
char *constant_name = constant_name = colon + 1;
|
|
|
|
char *class_name = estrndup(name, class_name_len);
|
|
|
|
char *lcname = zend_str_tolower_dup(class_name, class_name_len);
|
2003-06-15 21:58:50 +08:00
|
|
|
zval **ret_constant;
|
2003-06-16 18:16:50 +08:00
|
|
|
|
2006-10-19 00:35:15 +08:00
|
|
|
if (!scope) {
|
|
|
|
if (EG(in_execution)) {
|
|
|
|
scope = EG(scope);
|
|
|
|
} else {
|
|
|
|
scope = CG(active_class_entry);
|
|
|
|
}
|
2003-06-16 18:16:50 +08:00
|
|
|
}
|
2004-07-02 00:28:32 +08:00
|
|
|
|
2007-09-29 03:52:53 +08:00
|
|
|
if (class_name_len == sizeof("self")-1 &&
|
|
|
|
!memcmp(lcname, "self", sizeof("self")-1)) {
|
2003-07-01 04:22:35 +08:00
|
|
|
if (scope) {
|
2007-09-29 03:52:53 +08:00
|
|
|
ce = scope;
|
2003-06-16 18:16:50 +08:00
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
|
|
|
|
retval = 0;
|
|
|
|
}
|
2007-09-29 03:52:53 +08:00
|
|
|
efree(lcname);
|
|
|
|
} else if (class_name_len == sizeof("parent")-1 &&
|
|
|
|
!memcmp(lcname, "parent", sizeof("parent")-1)) {
|
|
|
|
if (!scope) {
|
2003-06-16 18:16:50 +08:00
|
|
|
zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
|
2007-09-29 03:52:53 +08:00
|
|
|
} else if (!scope->parent) {
|
|
|
|
zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
|
2003-06-16 18:16:50 +08:00
|
|
|
} else {
|
2007-09-29 03:52:53 +08:00
|
|
|
ce = scope->parent;
|
2003-06-16 18:16:50 +08:00
|
|
|
}
|
2007-09-29 03:52:53 +08:00
|
|
|
efree(lcname);
|
2007-09-29 15:28:34 +08:00
|
|
|
} else if (class_name_len == sizeof("static")-1 &&
|
|
|
|
!memcmp(lcname, "static", sizeof("static")-1)) {
|
|
|
|
if (EG(called_scope)) {
|
|
|
|
ce = EG(called_scope);
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
|
|
|
|
}
|
|
|
|
efree(lcname);
|
2003-06-15 21:58:50 +08:00
|
|
|
} else {
|
2007-09-29 03:52:53 +08:00
|
|
|
/* Check for namespace constant */
|
|
|
|
char *nsname;
|
|
|
|
unsigned int nsname_len;
|
|
|
|
|
|
|
|
/* Concatenate lowercase namespace name and constant name */
|
|
|
|
lcname = erealloc(lcname, class_name_len + 2 + const_name_len + 1);
|
|
|
|
lcname[class_name_len] = ':';
|
|
|
|
lcname[class_name_len+1] = ':';
|
|
|
|
memcpy(lcname + class_name_len + 2, constant_name, const_name_len + 1);
|
|
|
|
|
|
|
|
nsname = lcname;
|
|
|
|
nsname_len = class_name_len + 2 + const_name_len;
|
|
|
|
if (flags & ZEND_FETCH_CLASS_RT_NS_NAME) {
|
|
|
|
nsname = (char *)memchr(nsname, ':', nsname_len) + 2;
|
|
|
|
nsname_len -= (nsname - lcname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_hash_find(EG(zend_constants), nsname, nsname_len+1, (void **) &c) == SUCCESS) {
|
|
|
|
efree(lcname);
|
|
|
|
efree(class_name);
|
|
|
|
*result = c->value;
|
|
|
|
zval_update_constant_ex(&result, (void*)1, NULL TSRMLS_CC);
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
result->refcount = 1;
|
|
|
|
result->is_ref = 0;
|
|
|
|
return 1;
|
2003-06-15 21:58:50 +08:00
|
|
|
}
|
2007-09-29 03:52:53 +08:00
|
|
|
efree(lcname);
|
|
|
|
|
|
|
|
/* Check for class */
|
|
|
|
ce = zend_fetch_class(class_name, class_name_len, flags TSRMLS_CC);
|
2003-06-16 18:16:50 +08:00
|
|
|
}
|
2003-06-15 21:58:50 +08:00
|
|
|
|
2003-07-01 04:22:35 +08:00
|
|
|
if (retval && ce) {
|
2007-09-29 03:52:53 +08:00
|
|
|
if (zend_hash_find(&ce->constants_table, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
|
2003-06-16 18:16:50 +08:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2007-09-29 03:52:53 +08:00
|
|
|
if ((flags & ZEND_FETCH_CLASS_RT_NS_NAME) == 0) {
|
|
|
|
if ((flags & IS_CONSTANT_RT_NS_CHECK) != 0) {
|
|
|
|
name = constant_name;
|
|
|
|
name_len = const_name_len;
|
|
|
|
efree(class_name);
|
|
|
|
retval = 1;
|
|
|
|
return zend_get_constant(name, name_len, result TSRMLS_CC);
|
|
|
|
}
|
|
|
|
zend_error(E_ERROR, "Class '%s' not found", class_name);
|
|
|
|
}
|
2003-06-16 18:16:50 +08:00
|
|
|
retval = 0;
|
2003-06-15 21:58:50 +08:00
|
|
|
}
|
2007-06-07 16:37:40 +08:00
|
|
|
efree(class_name);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2003-07-01 04:22:35 +08:00
|
|
|
if (retval) {
|
2007-09-29 03:52:53 +08:00
|
|
|
zval_update_constant_ex(ret_constant, (void*)1, ce TSRMLS_CC);
|
2003-06-15 21:58:50 +08:00
|
|
|
*result = **ret_constant;
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
}
|
2007-04-04 08:42:42 +08:00
|
|
|
|
2003-06-15 21:58:50 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2007-04-04 08:42:42 +08:00
|
|
|
|
2007-09-29 03:52:53 +08:00
|
|
|
return zend_get_constant(name, name_len, result TSRMLS_CC);
|
2006-10-19 00:35:15 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2004-05-27 05:01:37 +08:00
|
|
|
char *lowercase_name = NULL;
|
|
|
|
char *name;
|
2000-07-28 17:44:46 +08:00
|
|
|
int ret = SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
#if 0
|
2001-08-11 23:56:40 +08:00
|
|
|
printf("Registering constant for module %d\n", c->module_number);
|
1999-04-08 02:10:10 +08:00
|
|
|
#endif
|
|
|
|
|
2002-06-19 12:13:12 +08:00
|
|
|
if (!(c->flags & CONST_CS)) {
|
2003-06-02 00:20:23 +08:00
|
|
|
/* keep in mind that c->name_len already contains the '\0' */
|
2006-03-15 22:12:26 +08:00
|
|
|
lowercase_name = estrndup(c->name, c->name_len-1);
|
|
|
|
zend_str_tolower(lowercase_name, c->name_len-1);
|
2004-05-27 05:01:37 +08:00
|
|
|
name = lowercase_name;
|
2003-05-22 06:57:51 +08:00
|
|
|
} else {
|
2004-05-27 05:01:37 +08:00
|
|
|
name = c->name;
|
2003-05-22 06:57:51 +08:00
|
|
|
}
|
2002-06-19 12:13:12 +08:00
|
|
|
|
2007-04-04 08:42:42 +08:00
|
|
|
if ((strncmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1) == 0) ||
|
|
|
|
zend_hash_add(EG(zend_constants), name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
|
2004-07-14 03:22:11 +08:00
|
|
|
zend_error(E_NOTICE,"Constant %s already defined", name);
|
2001-05-12 03:18:24 +08:00
|
|
|
free(c->name);
|
2002-06-22 21:52:07 +08:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
2001-08-14 23:22:34 +08:00
|
|
|
zval_dtor(&c->value);
|
|
|
|
}
|
2000-07-28 17:44:46 +08:00
|
|
|
ret = FAILURE;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2004-05-27 05:01:37 +08:00
|
|
|
if (lowercase_name) {
|
2004-07-02 00:28:32 +08:00
|
|
|
efree(lowercase_name);
|
2004-05-27 05:01:37 +08:00
|
|
|
}
|
2000-07-28 17:44:46 +08:00
|
|
|
return ret;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2003-02-01 09:49:15 +08:00
|
|
|
* indent-tabs-mode: t
|
1999-04-08 02:10:10 +08:00
|
|
|
* End:
|
|
|
|
*/
|