com php-src: Add load time return type checking to match user land logic: Zend/zend_API.c

From: Date: Thu, 05 Feb 2015 03:22:11 +0000
Subject: com php-src: Add load time return type checking to match user land logic: Zend/zend_API.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-84647@lists.php.net to get a copy of this message
Commit: 601fcc31af502fcf7aa36b8de53dfd4004fda613 Author: Reeze Xia <reeze@php.net> Thu, 5 Feb 2015 11:22:11 +0800 Parents: 2c84006f5ac11cb9b2409401cb381abb4d7a19e5 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=601fcc31af502fcf7aa36b8de53dfd4004fda613 Log: Add load time return type checking to match user land logic Changed paths: M Zend/zend_API.c Diff: diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 66381f3..80ff470 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2002,8 +2002,11 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio internal_function->num_args--; } if (info->type_hint) { - if (info->type_hint == IS_OBJECT) { - ZEND_ASSERT(info->class_name); + if (info->class_name) { + ZEND_ASSERT(info->type_hint == IS_OBJECT); + if (!strcasecmp(info->class_name, "self") && !scope) { + zend_error(E_CORE_ERROR, "Cannot declare a return type of self outside of a class scope"); + } } internal_function->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE; @@ -2206,6 +2209,18 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio zend_error(error_type, "Method %s::%s() cannot be static", scope->name->val, __debugInfo->common.function_name->val); } } + + if (ctor && ctor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && ctor->common.fn_flags & ZEND_ACC_CTOR) { + zend_error(E_CORE_ERROR, "Constructor %s::%s() cannot declare a return type", scope->name->val, ctor->common.function_name->val); + } + + if (dtor && dtor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && dtor->common.fn_flags & ZEND_ACC_DTOR) { + zend_error(E_CORE_ERROR, "Destructor %s::%s() cannot declare a return type", scope->name->val, dtor->common.function_name->val); + } + + if (clone && clone->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && dtor->common.fn_flags & ZEND_ACC_DTOR) { + zend_error(E_CORE_ERROR, "%s::%s() cannot declare a return type", scope->name->val, clone->common.function_name->val); + } efree((char*)lc_class_name); } return SUCCESS;

« previous php.cvs (#84647) next »