D
D
Donald_Duck2017-09-16 17:20:55
PHP
Donald_Duck, 2017-09-16 17:20:55

@return void or @return null?

Hello! Can't figure out when to use @return void .
Let's say there is some function that explicitly returns null

/**
 * @return null
 */
function a() {
    // Какой-то код в этой функции и дальше return
    return null;
}

Are there functions that return null implicitly?
/**
 * @return null или void?
 */
function b() {
    // Какой-то код в этой функции
}

/**
 * @return null или void?
 */
function c() {
    // Какой-то код в этой функции и дальше return
    return;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2017-09-16
@Donald_Duck

Documentation is written for people, so it should tell people something.
@return void tells us that the function does not return anything, so it does not make sense to use its call, let's say in expressions.
@return null says that we intentionally return null and we have a reason for this.
on the topic - https://www.dereuromark.de/2015/10/05/return-null-...

R
roxik, 2017-09-16
@roxik

No, it's still correct to return null.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question