]> granicus.if.org Git - php/commitdiff
Switch from ZEND_ACC_DYNAMIC to ZEND_ACC_ALLOW_STATIC and disallow calling
authorMarcus Boerger <helly@php.net>
Sat, 24 Jan 2004 16:59:24 +0000 (16:59 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 24 Jan 2004 16:59:24 +0000 (16:59 +0000)
internal non-static methods statically.
# As discussed with Zeev:
# - For BC standard userspace methods allow this with an E_STRICT message.
# - If you want to implement an internal method taht can be called both
#   statically and non-statically then use flag ZEND_ACC_ALLOW_STATIC.
# - Magic user space methods __*() cannot and __construct, __destruct,
# __clone can never be called statically.

Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_execute_API.c
tests/lang/bug23384.phpt

index ec6fb918dba4a54f8170ac66114c0820a068bed4..40e80ff366c11283252794a574fa17ac56a47e53 100644 (file)
@@ -1293,22 +1293,25 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
                scope->destructor = dtor;
                scope->clone = clone;
                if (ctor) {
-                       ctor->common.fn_flags |= ZEND_ACC_CTOR|ZEND_ACC_DYNAMIC;
+                       ctor->common.fn_flags |= ZEND_ACC_CTOR;
                        if (ctor->common.fn_flags & ZEND_ACC_STATIC) {
                                zend_error(error_type, "Constructor %s::%s cannot be static", ctor->common.scope->name, ctor->common.function_name);
                        }
+                       ctor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
                }
                if (dtor) {
-                       dtor->common.fn_flags |= ZEND_ACC_DTOR|ZEND_ACC_DYNAMIC;
+                       dtor->common.fn_flags |= ZEND_ACC_DTOR;
                        if (dtor->common.fn_flags & ZEND_ACC_STATIC) {
                                zend_error(error_type, "Destructor %s::%s cannot be static", dtor->common.scope->name, dtor->common.function_name);
                        }
+                       dtor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
                }
                if (clone) {
-                       clone->common.fn_flags |= ZEND_ACC_CLONE|ZEND_ACC_DYNAMIC;
+                       clone->common.fn_flags |= ZEND_ACC_CLONE;
                        if (clone->common.fn_flags & ZEND_ACC_STATIC) {
                                zend_error(error_type, "Constructor %s::%s cannot be static", clone->common.scope->name, clone->common.function_name);
                        }
+                       clone->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
                }
        }
        return SUCCESS;
index fe98fc24f429eb54e928b577b184cbf57363ea6a..1d32d0f12476e9f840712553bcca92666806cc18 100644 (file)
@@ -1043,6 +1043,8 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
                        CG(active_class_entry)->__get = (zend_function *) CG(active_op_array);
                } else if ((name_len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)))) {
                        CG(active_class_entry)->__set = (zend_function *) CG(active_op_array);
+               } else if (!(fn_flags & ZEND_ACC_STATIC)) {
+                       CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC;
                }
                free_alloca(short_class_name);
 
@@ -2389,19 +2391,19 @@ void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRML
        do_inherit_parent_constructor(ce);
 
        if (ce->constructor) {
-               ce->constructor->common.fn_flags |= ZEND_ACC_CTOR|ZEND_ACC_DYNAMIC;
+               ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
                if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
                        zend_error(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static", ce->name, ce->constructor->common.function_name);
                }
        }
        if (ce->destructor) {
-               ce->destructor->common.fn_flags |= ZEND_ACC_DTOR|ZEND_ACC_DYNAMIC;
+               ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
                if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
                        zend_error(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static", ce->name, ce->destructor->common.function_name);
                }
        }
        if (ce->clone) {
-               ce->clone->common.fn_flags |= ZEND_ACC_CLONE|ZEND_ACC_DYNAMIC;
+               ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
                if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
                        zend_error(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static", ce->name, ce->clone->common.function_name);
                }
index 70ad15f6b808b29007360a397a6c714cd57040bb..8c2026dfe84142f282f21cef49b282cb6ec6f9e0 100644 (file)
@@ -101,7 +101,7 @@ typedef struct _zend_brk_cont_element {
 #define ZEND_ACC_ABSTRACT_CLASS        0x10
 #define ZEND_ACC_FINAL_CLASS   0x20
 
-#define ZEND_ACC_DYNAMIC       0x80
+#define ZEND_ACC_ALLOW_STATIC  0x80
 
 /* The order of those must be kept - public < protected < private */
 #define ZEND_ACC_PUBLIC                0x100
index e74278935ef0aee950ba70520afe803e5c648912..08a77d1c6b63a92c96fe9e8fca640913339a2a41 100644 (file)
@@ -2520,10 +2520,10 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
        if (EX(function_state).function->common.scope) {
                if (!EG(This) && !(EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
                        int severity;
-                       if (EX(function_state).function->common.fn_flags & ZEND_ACC_DYNAMIC) {
-                               severity = E_ERROR;
-                       } else {
+                       if (EX(function_state).function->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
                                severity = E_STRICT;
+                       } else {
+                               severity = E_ERROR;
                        }
                        zend_error(severity, "Non-static method %s::%s() cannot be called statically", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
                }
index 63a0e4254bd7d935c3e94b98ab5c0e6f6fd7b984..3d2c4ccd28f94de203dc5033b57741aa939a304c 100644 (file)
@@ -718,10 +718,10 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
                EG(This) = NULL;
                if (calling_scope && !(EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
                        int severity;
-                       if (EX(function_state).function->common.fn_flags & ZEND_ACC_DYNAMIC) {
-                               severity = E_ERROR;
-                       } else {
+                       if (EX(function_state).function->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
                                severity = E_STRICT;
+                       } else {
+                               severity = E_ERROR;
                        }
                        zend_error(E_STRICT, "Non-static method %s::%s() cannot be called statically", calling_scope->name, EX(function_state).function->common.function_name);
                }
index e6184c4690809034943e2183afaea67592601c27..f48d89a3b0e15b9c098eefc05874296882f63f05 100644 (file)
@@ -1,5 +1,7 @@
 --TEST--
 Bug #23384 (use of class constants in statics)
+--INI--
+error_reporting=4095
 --FILE--
 <?php
 define('TEN', 10);
@@ -18,7 +20,8 @@ class Foo {
 Foo::test();   
 echo Foo::HUN."\n";
 ?>
---EXPECT--
+--EXPECTF--
+Strict Standards: Non-static method Foo::test() cannot be called statically in %sbug23384.php on line %d
 Array
 (
     [100] => ten