Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Programming: which is better, "file_exists" or "is_readable"?

edited September 2008 in Vanilla 1.0 Help
Just a general programming question, I looked around the internet and couldn't find any "best practice" articles stating if one or the other is better.

When attempting to include user-editable files, I'm inclined to use "is_readable" because it checks for two things: existence, access. What I don't know is how well it works cross-platform. There was a bug before PHP 5.1 where this function would ignore ACLs.

I've seen code where people use if (file_exists($File) && is_readable($File)) and that just seems ridiculous and slow.

What would you recommend?

Comments

  • Combining the two is just dumb--it appears equivalent to is_readable() alone.

    The PHP 5+ side of my brain says wrap the code in a try/catch since it's apparently not foolproof.
  • Of course!

    I always forget about the try/catch blocks. I'll have to do some tests right after I move my server to PHP 5 :)

    Thanks for the reminder.
This discussion has been closed.