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.
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;
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);
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);
}
#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
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);
}
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);
}
--TEST--
Bug #23384 (use of class constants in statics)
+--INI--
+error_reporting=4095
--FILE--
<?php
define('TEN', 10);
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