mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #77613 (method visibility change) (reverted ZEND_ACC_CTOR and ZEND_ACC_DTOR flags removal)
This commit is contained in:
commit
4474cf43e6
19
Zend/tests/bug77613.phpt
Normal file
19
Zend/tests/bug77613.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Bug #77613 (method visibility change)
|
||||
--FILE--
|
||||
<?php
|
||||
class A {
|
||||
public function __construct() {
|
||||
static $foo;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A { }
|
||||
|
||||
class C extends B {
|
||||
private function __construct() {}
|
||||
}
|
||||
?>
|
||||
OK
|
||||
--EXPECT--
|
||||
OK
|
@ -2314,11 +2314,13 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
|
||||
scope->__isset = __isset;
|
||||
scope->__debugInfo = __debugInfo;
|
||||
if (ctor) {
|
||||
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", ZSTR_VAL(scope->name), ZSTR_VAL(ctor->common.function_name));
|
||||
}
|
||||
}
|
||||
if (dtor) {
|
||||
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", ZSTR_VAL(scope->name), ZSTR_VAL(dtor->common.function_name));
|
||||
}
|
||||
|
@ -1213,7 +1213,7 @@ ZEND_FUNCTION(get_class_methods)
|
||||
if (!key) {
|
||||
ZVAL_STR_COPY(&method_name, mptr->common.function_name);
|
||||
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
|
||||
} else if (mptr->common.scope->constructor != mptr ||
|
||||
} else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
|
||||
mptr->common.scope == ce ||
|
||||
zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0) {
|
||||
|
||||
|
@ -6218,6 +6218,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
|
||||
CG(zend_lineno) = ast->lineno;
|
||||
|
||||
if (ce->constructor) {
|
||||
ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
|
||||
if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static",
|
||||
ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name));
|
||||
@ -6229,6 +6230,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
|
||||
}
|
||||
}
|
||||
if (ce->destructor) {
|
||||
ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
|
||||
if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static",
|
||||
ZSTR_VAL(ce->name), ZSTR_VAL(ce->destructor->common.function_name));
|
||||
|
@ -312,6 +312,12 @@ typedef struct _zend_oparray_context {
|
||||
/* op_array is preloaded | | | */
|
||||
#define ZEND_ACC_PRELOADED (1 << 27) /* | X | | */
|
||||
/* | | | */
|
||||
/* functions is a constructor | | | */
|
||||
#define ZEND_ACC_CTOR (1 << 28) /* | X | | */
|
||||
/* | | | */
|
||||
/* function is a destructor | | | */
|
||||
#define ZEND_ACC_DTOR (1 << 29) /* | X | | */
|
||||
/* | | | */
|
||||
/* op_array uses strict mode types | | | */
|
||||
#define ZEND_ACC_STRICT_TYPES (1 << 31) /* | X | | */
|
||||
|
||||
|
@ -272,7 +272,7 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
|
||||
/* Checks for constructors only if they are declared in an interface,
|
||||
* or explicitly marked as abstract
|
||||
*/
|
||||
if ((fe->common.scope->constructor == fe)
|
||||
if ((fe->common.fn_flags & ZEND_ACC_CTOR)
|
||||
&& ((proto->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0
|
||||
&& (proto->common.fn_flags & ZEND_ACC_ABSTRACT) == 0)) {
|
||||
return 1;
|
||||
@ -574,7 +574,7 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
|
||||
zend_function *proto = parent->common.prototype ?
|
||||
parent->common.prototype : parent;
|
||||
|
||||
if (parent->common.scope->constructor != parent) {
|
||||
if (!(parent_flags & ZEND_ACC_CTOR)) {
|
||||
if (!proto) {
|
||||
proto = parent;
|
||||
}
|
||||
@ -1947,7 +1947,7 @@ static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract
|
||||
if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
|
||||
ai->afn[ai->cnt] = fn;
|
||||
}
|
||||
if (fn->common.scope->constructor == fn) {
|
||||
if (fn->common.fn_flags & ZEND_ACC_CTOR) {
|
||||
if (!ai->ctor) {
|
||||
ai->cnt++;
|
||||
ai->ctor = 1;
|
||||
|
@ -482,7 +482,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
|
||||
size_t len = ZSTR_LEN(mptr->common.function_name);
|
||||
|
||||
/* Do not display old-style inherited constructors */
|
||||
if (mptr->common.scope->constructor != mptr
|
||||
if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0
|
||||
|| mptr->common.scope == ce
|
||||
|| !key
|
||||
|| zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0)
|
||||
@ -753,10 +753,10 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
|
||||
if (fptr->common.prototype && fptr->common.prototype->common.scope) {
|
||||
smart_str_append_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name));
|
||||
}
|
||||
if (fptr->common.scope && fptr->common.scope->constructor == fptr) {
|
||||
if (fptr->common.fn_flags & ZEND_ACC_CTOR) {
|
||||
smart_str_appends(str, ", ctor");
|
||||
}
|
||||
if (fptr->common.scope && fptr->common.scope->destructor == fptr) {
|
||||
if (fptr->common.fn_flags & ZEND_ACC_DTOR) {
|
||||
smart_str_appends(str, ", dtor");
|
||||
}
|
||||
smart_str_appends(str, "> ");
|
||||
@ -3396,7 +3396,7 @@ ZEND_METHOD(reflection_method, isConstructor)
|
||||
/* we need to check if the ctor is the ctor of the class level we we
|
||||
* looking at since we might be looking at an inherited old style ctor
|
||||
* defined in base class. */
|
||||
RETURN_BOOL(intern->ce->constructor == mptr);
|
||||
RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_CTOR && intern->ce->constructor && intern->ce->constructor->common.scope == mptr->common.scope);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -3411,7 +3411,7 @@ ZEND_METHOD(reflection_method, isDestructor)
|
||||
return;
|
||||
}
|
||||
GET_REFLECTION_OBJECT_PTR(mptr);
|
||||
RETURN_BOOL(intern->ce->destructor == mptr);
|
||||
RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_DTOR);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user