如何确定函数是否不返回任何内容?
问题描述:
是否有一种方法可以在PHP中使用Reflection或其他方式?
Is there a way to do this in PHP, using Reflection or something?
function a{
return null;
}
function b{
}
$a = a(); // null
$b = b(); // null :(
答
如果您未明确返回某些内容,则默认情况下函数将返回 null
.这就是函数在PHP中的工作方式,无法找出函数是否具有返回值.
If you do not explicitly return something then functions will return null
by default. That is just how functions work in PHP, and there is no way of finding out if the function has a return value.
但这应该不是问题.如果函数返回null,通常意味着什么也没做,或者什么也没找到,等等.
This should not be a problem, though. If a function returns null it usually means that nothing was done, or that nothing was found, etc.