Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 9

6apxatCurtisOdenericgillettelortabac +5 guests

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

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

  • Posts: 2,301
    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.