Hinter den Kulissen, PHP checks for return
statements in void
functions und, wenn sie einen Rückgabewert angeben, wirft einen Fehler bei der Kompilierung:
/* `return ...;` is illegal in a void function (but `return;` isn't) */
if (return_info->type_hint == IS_VOID) {
if (expr) {
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;
}
Ansonsten Zusammenstellung von void
Funktionen wie normalen funktioniert. return
without a value implicitly returns NULL
:
if (!expr_ast) {
expr_node.op_type = IS_CONST;
ZVAL_NULL(&expr_node.u.constant);
Und jede Funktion is compiled with an implicit return
at the end:
zend_emit_final_return(0);
Whose return value is NULL
:
zn.op_type = IS_CONST;
if (return_one) {
ZVAL_LONG(&zn.u.constant, 1);
} else {
ZVAL_NULL(&zn.u.constant);
}
'Ist diese Funktion implizit nichtig auch Rückkehr' - ja –
NULL http://ideone.com?/AXErws oder https://3v4l.org/RJRoR –