]> granicus.if.org Git - php/commitdiff
Allow functions in internal namespaces (for example factories)
authorMarcus Boerger <helly@php.net>
Sun, 4 May 2003 22:49:31 +0000 (22:49 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 4 May 2003 22:49:31 +0000 (22:49 +0000)
Zend/zend_API.c
Zend/zend_API.h

index fcfd7dff6119c81e0cf98fbe4eb669a7fe9fae42..5fac428ac40079c5846bf54313edcc202bf933ae 100644 (file)
@@ -1146,7 +1146,7 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi
        int error_type;
        zend_function *ctor = NULL, *dtor = NULL, *clone = NULL;
        char *lowercase_name;
-       int fname_len;
+       int fname_len, is_namespace = 0;
        zend_namespace *scope_namespace;
 
        if (type==MODULE_PERSISTENT) {
@@ -1162,6 +1162,7 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi
 
        if(scope) {
                scope_namespace = scope->ns;
+               is_namespace = (scope->type == ZEND_INTERNAL_NAMESPACE || scope->type == ZEND_USER_NAMESPACE) ? 1 : 0;
        } else {
                scope_namespace = EG(active_namespace);
        }
@@ -1189,18 +1190,23 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi
                        break;
                }
                if (scope) {
-                       /*
-                        * If it's an old-style constructor, store it only if we don't have
-                        * a constructor already.
-                        */
-                       if (!strcmp(ptr->fname, scope->name) && !ctor) {
-                               ctor = reg_function;
-                       } else if (!strcmp(ptr->fname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
-                               ctor = reg_function;
-                       } else if (!strcmp(ptr->fname, ZEND_DESTRUCTOR_FUNC_NAME)) {
-                               dtor = reg_function;
-                       } else if (!strcmp(ptr->fname, ZEND_CLONE_FUNC_NAME)) {
-                               clone = reg_function;
+                       if (is_namespace) {
+                               /* if namespace all methods must be "static final" */
+                               reg_function->common.fn_flags = ZEND_ACC_FINAL | ZEND_ACC_STATIC;
+                       } else {
+                               /* if class not namespace then look for ctor, dtor, clone
+                                * If it's an old-style constructor, store it only if we don't have
+                                * a constructor already.
+                                */
+                               if (!strcmp(ptr->fname, scope->name) && !ctor) {
+                                       ctor = reg_function;
+                               } else if (!strcmp(ptr->fname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
+                                       ctor = reg_function;
+                               } else if (!strcmp(ptr->fname, ZEND_DESTRUCTOR_FUNC_NAME)) {
+                                       dtor = reg_function;
+                               } else if (!strcmp(ptr->fname, ZEND_CLONE_FUNC_NAME)) {
+                                       clone = reg_function;
+                               }
                        }
                }
                ptr++;
@@ -1438,6 +1444,10 @@ ZEND_API zend_namespace *zend_register_internal_namespace(zend_namespace *orig_n
        zend_hash_update(&CG(global_namespace).class_table, lowercase_name, ns->name_length+1, &ns, sizeof(zend_namespace *), NULL);
        free(lowercase_name);
 
+       if (ns->builtin_functions) {
+               zend_register_functions(ns, ns->builtin_functions, &ns->function_table, MODULE_PERSISTENT TSRMLS_CC);
+       }
+
        return ns;
 }
 
index 5fa9b446242ff8b8a4d3bba1f32695613e1cf0c4..d8ebb20ac87178fdd350684f9c11a9265f8a6b0b 100644 (file)
@@ -106,6 +106,7 @@ BEGIN_EXTERN_C()
 
 #define INIT_NAMESPACE(ns_container, ns_name) INIT_CLASS_ENTRY(ns_container, ns_name, NULL)
 
+#define INIT_NAMESPACE_WITH_FUNCS(ns_container, ns_name, functions) INIT_CLASS_ENTRY(ns_container, ns_name, functions)
 
 
 int zend_next_free_module(void);