Jump to content

File Handles


Lectrician

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.