summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-06-04 13:25:52 +0200
committerNikita Popov <nikic@php.net>2016-06-04 13:27:11 +0200
commit73b2f791997a254788b1939ca8cef373694f8461 (patch)
tree1dd5f3f6677ce81c8ea25358b2c43e97946efdd6 /Zend/zend_compile.c
parentfe907562ada8929863561b27355e802db4f14a79 (diff)
downloadphp-git-73b2f791997a254788b1939ca8cef373694f8461.tar.gz
More explicit errors for return; vs return null;
Both for "return null" in a void function and "return" in a nullable return function.
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r--Zend/zend_compile.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 4bcec416a7..2a575cff62 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2270,7 +2270,13 @@ static void zend_emit_return_type_check(
/* `return ...;` is illegal in a void function (but `return;` isn't) */
if (return_info->type_hint == IS_VOID) {
if (expr) {
- zend_error_noreturn(E_COMPILE_ERROR, "A void function must not return a value");
+ if (expr->op_type == IS_CONST && Z_TYPE(expr->u.constant) == IS_NULL) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "A void function must not return a value "
+ "(did you mean \"return;\" instead of \"return null;\"?)");
+ } else {
+ zend_error_noreturn(E_COMPILE_ERROR, "A void function must not return a value");
+ }
}
/* we don't need run-time check */
return;
@@ -2280,8 +2286,14 @@ static void zend_emit_return_type_check(
zend_op *opline;
if (!expr && !implicit) {
- zend_error_noreturn(E_COMPILE_ERROR,
- "A function with return type must return a value");
+ if (return_info->allow_null) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "A function with return type must return a value "
+ "(did you mean \"return null;\" instead of \"return;\"?)");
+ } else {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "A function with return type must return a value");
+ }
}
if (expr && expr->op_type == IS_CONST) {