summaryrefslogtreecommitdiff
path: root/Zend/zend_builtin_functions.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-05-12 07:11:55 +0000
committerDmitry Stogov <dmitry@php.net>2008-05-12 07:11:55 +0000
commit907fa6650719ee7a2107c53ea33b3d7a6df2877f (patch)
tree8399b52aa4c952cd38e1372fe98d133c740b88eb /Zend/zend_builtin_functions.c
parent77feabfc717cd6ca26df9f1046ad00b62030633f (diff)
downloadphp-git-907fa6650719ee7a2107c53ea33b3d7a6df2877f.tar.gz
Added API to use namesapces in internal extensions
Diffstat (limited to 'Zend/zend_builtin_functions.c')
-rw-r--r--Zend/zend_builtin_functions.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 007378784d..9006e15fde 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -50,6 +50,7 @@ static ZEND_FUNCTION(property_exists);
static ZEND_FUNCTION(class_exists);
static ZEND_FUNCTION(interface_exists);
static ZEND_FUNCTION(function_exists);
+static ZEND_FUNCTION(class_alias);
#if ZEND_DEBUG
static ZEND_FUNCTION(leak);
#ifdef ZEND_TEST_EXCEPTIONS
@@ -115,6 +116,7 @@ static const zend_function_entry builtin_functions[] = {
ZEND_FE(class_exists, NULL)
ZEND_FE(interface_exists, NULL)
ZEND_FE(function_exists, NULL)
+ ZEND_FE(class_alias, NULL)
#if ZEND_DEBUG
ZEND_FE(leak, NULL)
#ifdef ZEND_TEST_EXCEPTIONS
@@ -1146,6 +1148,49 @@ ZEND_FUNCTION(function_exists)
}
/* }}} */
+/* {{{ proto bool class_alias(string user_class_name , string alias_name [, bool autoload])
+ Creates an alias for user defined class */
+ZEND_FUNCTION(class_alias)
+{
+ char *class_name, *lc_name, *alias_name;
+ zend_class_entry **ce;
+ int class_name_len, alias_name_len;
+ int found;
+ zend_bool autoload = 1;
+ ALLOCA_FLAG(use_heap)
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &class_name, &class_name_len, &alias_name, &alias_name_len, &autoload) == FAILURE) {
+ return;
+ }
+
+ if (!autoload) {
+ lc_name = do_alloca(class_name_len + 1, use_heap);
+ zend_str_tolower_copy(lc_name, class_name, class_name_len);
+
+ found = zend_hash_find(EG(class_table), lc_name, class_name_len+1, (void **) &ce);
+ free_alloca(lc_name, use_heap);
+ } else {
+ found = zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC);
+ }
+ if (found == SUCCESS) {
+ if ((*ce)->type == ZEND_USER_CLASS) {
+ if (zend_register_class_alias_ex(alias_name, alias_name_len, *ce TSRMLS_CC) == SUCCESS) {
+ RETURN_TRUE;
+ } else {
+ zend_error(E_WARNING, "Cannot redeclare class %s", alias_name);
+ RETURN_FALSE;
+ }
+ } else {
+ zend_error(E_WARNING, "First argument of class_alias() must be a name of user defined class");
+ RETURN_FALSE;
+ }
+ } else {
+ zend_error(E_WARNING, "Class '%s' not found", class_name);
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
#if ZEND_DEBUG
/* {{{ proto void leak(int num_bytes=3)
Cause an intentional memory leak, for testing/debugging purposes */