开发者

Is there a way to do this check without two if statements in PHP?

i have this if statement

if(file_exists( $_SERVER{'DOCUMENT_ROOT'}.$writabledir.$name) && filemtime($_SERVER{'DOC开发者_JAVA技巧UMENT_ROOT'}.$writabledir.$name) < $olddate)  { 

if the file is there all is well but if the file is not there I get this error

 Warning: filemtime(): stat failed for /User....

I know I can do an if and then an inner if but is there a better way?


If file_exists is returning false, then the filemtime call should never happen. && is a short-circuiting logical AND in PHP, meaning that if it doesn't need to make the second call (i.e. first part of the logical statement is false, therefore there is no way the whole statement could be true), it won't. There might be something else weird going on in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜