PeeHaa PeeHaa - 1 month ago 4
PHP Question

Should a function use: return null;?

Should a function return



function test()
return null; // vs return;

Is the latter considered bad practice or doesn't it matter?


Whether it is bad practice shouldn't be subjective IMHO.


If you don't return anything, just use return; or omit it at all at the end of the function.
If your function is usually returns something but doesn't for some reason, return null; is the way to go.

That's similar to how you do it e.g. in C: If your function doesn't return things, it's void, otherwise it often return either a valid pointer or NULL.