Jump to content

Recommended Posts

Ok.  I am asking some basic type questions I guess!

 

When you open a file with a filehandle, is it safe to use the same file handle a couple times in a script, for different files, assuming one is closed before the other opened?

 

I use $fh a lot in my scripts, and wonder if this is bad practice?  I copy and paste code quite often to speed up my writing, and retain this filehandle usually.

 

Link to comment
https://forums.phpfreaks.com/topic/290646-file-handles/
Share on other sites

You can reuse a variable as often as you want.

 

However, “fn” isn't exactly a particularly meaningful name. This may be OK if your code is so short that one can derive the meaning from the context, but it's generally a good idea to give your variables proper names which speak for themselves.

 

You do a lot of copypasting? That's a bad sign. Use functions to avoid repeating the same logic over and over again. Note that PHP itself has a lot of functions that may be useful. For example, cumbersome low-level file access can often be replaced with a single file_get_contents() or file_put_contents() call.

Link to comment
https://forums.phpfreaks.com/topic/290646-file-handles/#findComment-1488904
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.