开发者

Why is (If false return "true") ... returning true?

Inside the begining of a function I have this:

if(false);
{
    return 'TRUE';
}

it is returning "TRUE"! Obviously my real use w开发者_如何学编程as checking a more useful expression and returning something else. I just changed it to this to elaborate my point.

Why is this happening? Can you not put a return inside an if statement? I do this all the time in other languages.

For example

instead of this:

function () {
if(something)
{
//process stuff
}
}

which requires wraping everthing inside the function inside an if.

I prefer to do this:

function() {
if(!something)
return;
//process stuff
}

Is this not OK in PHP... is there a work around?


You're just crazy. :)

if(false); //   <----- remove semi colon
{
    return 'TRUE';
}

should have one less semi-colon.

if(false)
{
    return 'TRUE';
}


You have an extra semicolon after the if condition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜